Blazor Intellisense in .razor file stops working after publishing - visual-studio

I have a Blazor application using Visual Studio 2019 version 16.10.4. Every time I publish to an IIS server using the Publish... command from the Solution Explorer, Intellisense stops working in the .razor file that I have open and all text coloring goes away, so that all the text becomes the same color (and all auto-indentation stops working). If I close the .razor file and reopen it, Intellisense and colors start working again.
Is that a known issue, or is it a problem that I can fix? I've seen other posts about Intellisense not working in Blazor, but those all seem to be older posts with older minor version numbers of Visual Studio, and they don't mention the problem occurring only when publishing.

This kind of thing happens all the time. The solution is to jiggle it a little bit: close and re-open the file, restart VS, delete bin files, etc. etc.
In Blazor, there are a couple other common culprits. EventCallback with a declared Type often complains that it can't covert the type, even though if you ignore it, it will still compile and run.

It appears a fix is coming for this. As much as it's a frustrating issue, at least it will be resolved soon.
https://github.com/dotnet/razor-tooling/issues/5103

Related

Visual Studio 2022 Razor Editor Crashes Occasionally

Sometimes after editing some parts of a razor source file, the editor crashes with tons of errors like the following screenshot:
It fails to recognize these external components from NuGet packages and other source files.
This problem has been around for quite a while. Since it could be simply fixed by reloading the project, I didn't pay much attention to it at first. However, it started to appear frequently recently, I have to reload the project every few minutes, which is really annoying.
Maybe someone has also encountered this problem? It sucks to have to reload the project all the time!
To be mentioned, I'm using ReSharper 2021.3 along with VS2022, but ReSharper's global analyzers still work fine when VS's crashes.

How to collapse solution explorer view of razor pages?

I was coding with razorpages when randomly about 2 days ago the razor pages now display boths the cshtml and cs right away. earlier I could expand the cshtml to get to the cs file and i think it was a more compact that way
i think its options somewhere in tools->options->environment () but there are so many
after a few different google searches I found nothing helpful.
here is a picture of the problem:
earlier I could expand the cshtml to show the .cs files now i just see all of them and its kind of overwhelming.
enable file nesting in solution explorer
They're not being nested, is all. It's literally two separate files, Visual Studio just recognizes that it's a Core project, and then shows them nested, since it understands that they're related. If that's not happening, then that means Visual Studio doesn't recognize it as a Razor Page, which could be a problem with VS, the project, or something else entirely. It's essentially impossible to say what the issue might be, so you'll just need to try stuff. A few things I can think of to try:
If you're not using VS 2019, upgrade. Ultimately, this is part of the ASP.NET Core tooling, and best version of that is always going to be in the latest release.
Verify that you solution is building correctly. You might also consider deleting all bin and obj directories and rebuilding to ensure the build is truly up to date.
Close Visual Studio completely and re-open it. You may consider restarting as well. (You've probably already tried this though).
Try running Visual Studio in "safe-mode", which essentially just means disabling all the extensions you have installed. You can either manually disable all your extensions and then restart or close Visual Studio and start it via the command like with devenv /safemode. If this fixes the issue, then there's an extension causing issues. You'll probably need to just disable each one by one to see which on is causing the problem, and then either remove it or see if there's an update that corrects it.
If all else fails, repair Visual Studio. Run the intaller, and click the "More" link under the installation you're working with. Then click "Repair".

Visual Studio sometimes not saving files

I am getting an inconsistent error with Visual Studio 2015 that is severely hampering my productivity.
I am working on a very large application that I have pulled down from TFS. Sometimes when working I will try and save the file that I was working on, and have the asterix not go away and the file not save. This is despite running the application in Administrator.
Sometimes the solution is simply to rebuild the project and then try to save, however when this doesn't work I need close down visual studio and start up again, losing all my saves anyways.
This isn't too bad when I am working on .net files because the problem happens a lot less, and the solution is almost always to just rebuild, which is much better than having to re boot vs. However recently I have been working on javascript files within visual studio, and with them I get about one save, then the problems comes up, and rebuilding doesn't fix issue, causing me to have to reboot visual studio every save I make...
I have tried searching online for people who have faced a similar issue, or asked around my work, and no one seems to have ever had a similar problem. So hopefully, for my sanity's sake, someone knows what the heck is going on with my visual studio. Thanks!
I am currently running VS2019 16.7.2 and sometimes it just refuses to save no matter what I do. I try Ctrl + S, File -> "Save all", closing the window (which causes the changes to be lost) but nothing works.
Though for some reason when first I press the File -> "Save ... as" option in the menu and then cancel it, that releases the "save lock" and suddenly I am able to save again. Not really a satisfactory solution but at least all changes aren't lost. Maybe it will work on other versions as well?
I will give an answer to a problem which might not be exactly the same as the one reported by the author, but it is fairly close, and people searching for a solution to this problem are likely to arrive to this question.
In my case, in my entire solution containing thousands of files, there was only one particular file that Visual Studio was consistently failing to save when needed. As a result, after each commit, the "Git Changes" tab would not appear completely empty. All files would be committed, except this one file, which would appear as still uncommitted. So, I would have to manually save it and then amend the last commit in order to arrive at a completely empty "Git Changes" tab.
I thought that the problem might be due to some discrepancy between the letter case of the filename on disk (which is what the "Git Changes" view reports) and the letter case of the filename in the visual studio project file (which is what the "Solution Explorer" view reports) but it turns out that this was not it.
After much troubleshooting, I discovered that the following sequence of magical incantations solves the problem, I have no idea why:
In "Solution Explorer" locate the problematic file.
Rename the problematic file to something else.
Commit (with amend if you wish) the file.
Rename the file back to its original name.
Commit (with amend) the file again.
Restart Visual Studio.
The last step of restarting Visual studio is not strictly speaking necessary, but it is useful in case you have a letter case mismatch, because Visual Studio seems to be somehow caching filenames, (or at any rate not detecting that the capitalization of a filename has changed,) and restarting it makes it come to its senses.
I realize this is an old question but I had a similar problem with a solution file I had upgraded from Visual Studio 2015 to Visual Studio 2022. I was unable to save any changes to the solution, although the file was writable in notepad.
Deleting the section in the solution file as suggested by Richard Stanton's workaround fixed it for me!
developercommunity.visualstudio.com Workaround
Delete the following section from the solution file:
ProjectSection(FolderStartupServices) = postProject
{B4F97281-0DBD-4835-9ED8-7DFB966E87FF} = {B4F97281-0DBD-4835-9ED8-7DFB966E87FF}
EndProjectSection

Visual Studio 2013 Aborting When Opening Property Sheets for Project

I don't know when this started, but I discovered that Visual Studio 2013 Update 5 aborts when attempting to open properties for a project within a solution. It seems to only happen when we have more than one project in the solution.
I've been able to reproduce it in two circumstances:
The first project is C++ and the second project is Fortran. Right-clicking on the first project and selecting Properties crashes Visual Studio without a crash dump or any kind of pop-up notification. Visual Studio just ceases to exist. Right-clicking on the Fortran project brings up the property sheet without any problem.
The second circumstance is with two projects, both C++. In this case, I'm able to open properties successfully for the first project, but not for the second one.
In every case I've tried where there's a one-to-one solution and project, it's working fine. A colleague who's working with VS 2013 Update 4 verified that the crash occurs for him as well.
We don't know when this started, but historically, we've opened these property sheets many, many times. However, it's probably been a few months since I've worked on a mixed-language process, and same with my colleague.
I've turned on logging and there was a complaint in the log about two versions of the Desktop SDK having the same internal ID. I removed one of those altogether, but that didn't seem to affect anything. It's also not clear if that error has any relationship to the crash.
I've also done a repair on Visual Studio, and that did not correct the problem.
I've also tried deleting the .suo and .user files. Again, no luck.
I've done quite a bit of googling but haven't found anything that matches this specific problem.
Any ideas?
Thank you,
Doug

Visual Studio project execution stopped shortly after starting

Yesterday I wanted to continue working on a project of mine, so I started Visual Studio and asked it to run the project to remind myself, what was already implemented and what wasn't.
The project got built and started, but seemed to quit right away. No error message, nothing.
No matter what I did, whether I rebuilt the project or cleaned it, nothing changed.
This didn't make sense, since the last time I tested the project, it worked perfectly (and I didn't modify anything in the code since then)
So, I assumed I had a hidden bug somewhere in the code, that just didn't show up previously.
I put a Breakpoint somewhere near the beginning of the code, and ran the project.
As expected, Visual Studio paused the execution at the Breakpoint and highlighted it.
I decided to set another Breakpoint somewhere later in the code and continue execution, but before I could even move my mouse, the project stopped.
Restarting Visual Studio didn't help, but restarting the PC did. Therefore, I'm assuming that something on my system was terminating my project, shortly after execution begun.
Now my question is: What exactly happened, and especially: why did it happen?
The problem came back while I was writing this question. I don't feel like restarting my PC every couple of hours...
I really appreciate the time you took reading this and I look forward to your answers.
I'm aware that I'm answering my own question, but since I've solved it myself, I thought others might want to know how I did it (for the sake of future generations)
The thing is: I've recently added Visual C++ to Visual C# before Visual C# started having problems.
So I deduced, that maybe the installer for Visual Studio messed up with something and decided to reinstall Visual Studio.
Problem solved.
So: if your projects stop without warning even while paused on a Breakpoint and you've changed something in your Visual Studio installation (like added Visual C++ in my case), you might need to reinstall the whole thing.
Luckily, the Visual Studio installer offers a "Reinstall" option, so you don't need to uninstall and reinstall manually.
I found about this solution, after talking to a more experienced colleague. I just wish I asked him first. Still appreciate your efforts in the matter, though.
EDIT:
I recently noticed a similar bug acting up for C++ programs this time, where the window border would be outlined in red. The thing is: it's not Visual Studio's fault, but in fact Avast Antivirus' fault. More specifically, its Sandbox mode.
So, if for any reason, you notice programs quitting without crashing, shortly after starting and their window border having a red outline, you're very likely using Avast Antivirus and should deactivate the Sandbox mode.
Happens to me from time to time.
Sometimes closing and opening VS helps, sometimes you have to restart the computer.
I assume it must be related to some DLL or something that is loaded into memory and corrupt, or something like VS loosing the reference to it, and not unloading it correctly/replacing it.
I also once had this strange bug, where I started VS, just like any other day, and my project crashes instantly with some H_RESULT error (some DLL related Error) upon run. After having spent around 1hour searching for the source of the problem, I went into the reference section, and what did I see there : the worst possible circular reference ever : my business project had a reference to ... itself ! The kind of stuff you could not do if you wanted to.
The weirdest part of this, must of been that VS managed to compile the project, and it only crashed while trying to run it ...

Resources