Visual Studio errors disappear when open file - c#

I'm in the process of updating a library in a larger solution. For this purpose, I have removed the old references in all projects and added new ones.
If I compile the solution now I get about 3000 build errors, which indicate that various classes are defined in the old, removed libraries and I should add a reference to them.
After I have opened a reported file, Visual Studio recognizes that these classes are also included in the new libraries and removes the error.
Now I don't want to open hundreds of files to make these ghost errors disappear, especially because the problem repeats itself after the next build.
Does anyone have any idea how I can get Visual Studio to stop reporting ghost bugs?
I'm using Visual Studio 2022.

Related

Why does Visual Studio 2022 suddenly stop showing errors?

As stated in the headline, Visual Studio 2022 suddenly stopped showing errors (and also I can't find public method and variables but that's another question).
I am working in Unity and suddenly it just don't want to cooperate anymore.
I tried closing the application and unity all together and restarted my computer, and nothing worked.
At the top of your screenshot you can see "Miscellaneous Files". This means that the file is not considered to be part of any project.
To see errors and IntelliSense, VS requires source files to exist within a project so that it knows:
What references exist (packages, assemblies, target framework)
What version of the language is being used
Various properties that influence analysis/analyzers
So for some reason your file is not considered part of a project. We can't see your Solution Explorer, so it's not clear why that might be. Most likely you've opened the file via "File | Open". Make sure you create the file within a project, or add it to a project.
One of the endless joys of working with Visual Studio are random inexplicable times it stops working the way it should. Usually these steps work:
Close VS completely
Ensure all bin and obj directories of all projects are cleared
In the same directory as your solution should be a hidden .vs directory. Delete this.
Reopen VS and your solution. You should be back to a normal state within a few moments. Sometimes a "Rebuild All" can accelerate its return to normality too.

Why do my namespace references keep breaking in Visual Studio?

I asked this question on the Unity Forums but unfortunately no response there. Since this seems to be an error/issue with Visual Studio itself I am asking here as well.
Situation
I am unable to compile my project code in Visual Studio. It still compiles and runs in the Unity Editor but Visual Studio gives hundreds of missing reference errors ("The type or namespace name 'XXX' could not be found (are you missing a using directive or an assembly reference?)"). This includes files which I wrote but which are in another assembly, i.e. my own created namespaces.
Nothing I've tried works (see below) except for one thing. If I manually remove the references to all four assemblies in visual studio and re-add them, the solution will compile. But when I then close VS and reopen the same error comes up. From more testing I found that now and then (don't know what triggers it) the references will even break without closing Visual Studio.
The assemblies are Assembly-CSharp, Assembly-CSharp-Editor, Assembly-CSharp-Editor-firstpass and Assembly-CSharp-firstpass; the normal ones that get created with a Unity project. The scripts which now do not reference correctly in the assembly did not cause any problems before and I did not change them at all. I do not know what I would have done that is now causing this to break. Previously there were no errors coming up with these scripts; one moment they were compiling fine and the next these errors were coming up.
Versions
Unity 2019.3.12f1 Personal.
Visual Studio Community 2017 15.9.22.
I've tried:
all of these Visual Studio refuses to build project due to missing assembly reference that isn't missing
all of these "Are you missing an assembly reference?" compile error - Visual Studio
Removing the .vs folder and all VS files from the Unity project folder and letting the editor regenerate them. Also regenerated manually from within unity
Making sure Visual Studio (and the Visual Studio Tools for Unity (which is installed using the Visual Studio installer)) are fully up to date.
Updated VS to the latest version
Removed VS Code package (I'm not using Code) from Unity, then readded.
A number of restarts of Unity and VS in between all the above.
EDIT: all of these http://www.codeandyou.com/2017/08/missing-assembly-reference-in-visual.html
Edit:
I've deleted large parts of the project in a copy to see when it would solve. It does not solve all the way down to removing the last script. Then removing that last script and adding a different one again results in the error. I don't see this is anything wrong with the scripts themselves but must be something with VS settings or behavior.
This issue has popped up again (I'm using 2020.2.1f1).
I fixed it by selecting Assets->Reimport All in the editor.
Turns out it was a bug in Unity. New update came out which fixed it. 8 hours of my life later...
I am using Unity 2020.3.18f1, with Visual Studio 2019.. Spend hours figuring out. I have tried:-
Deleting "*.csproj"
Unity > Edit > Preferences > External Tools > "Regenerate project files"
Unity > Edit > Preferences > External Tools > External script editor > Visual Studio
Rebuild Solution
Right click on .cs file in unity > Open C# project on the script
Reimport script
Create new script and open, to trigger recompilation
None of these is working for my case. Problem gone after I reload the assembly in "Solution Explorer" of Visual Studio. Do to the rest of "unloaded" assembly.

Visual Studio 2013 or 2015 EditorPackage did not load correctly constantly

When starting Visual Studio 2013 Pro (Update 4 installed) I very often get this error message (several times a day now) for the past about two weeks:
The 'Microsoft.VisualStudio.Editor.Implementation.EditorPackage' package did not load correctly.
I know I can correct this problem by closing Visual Studio and deleting:
%LocalAppData%\Microsoft\VisualStudio\12.0\ComponentModelCache
I have never seen it before that time and as far as I found out in the Internet it was possibly introduced with Update 3.
Well, the problem is that it is annoying to restart Visual Studio several times a day, and I was wondering if anyone else is experiencing this and knows how to solve it for good or what the cause is.
I noticed that it happens extremely often if I work in more than one instance of Visual Studio in parallel. This one is a killer. But still I suspect a third-party component to be involved or it is the size of one of the solutions (about 70 projects). I tried to deactivate some extensions I newly installed and need for the big project, but to no avail.
Just as information: I am working with C#. When working in parallel with projects open in several instances of Visual Studio I never had problems before.
Does anyone have the same problem to this extend or possibly have a better solution than deleting the folder and restarting?
This has become a popular question so I thought I add an explicit answer how to (at least) temporarily fix the problem as already stated in the question:
I stop Visual Studio and delete the following folder (completely, not just contents)
%LocalAppData%\Microsoft\VisualStudio\12.0\ComponentModelCache
If you are using VS2015, then the path should be:
%LocalAppData%\Microsoft\VisualStudio\14.0\ComponentModelCache
If you are using VS2017, then the path should be:
%LocalAppData%\Microsoft\VisualStudio\15.0\ComponentModelCache
I don't keep a backup of the folder. It is created automatically again when starting Visual Studio.
I have never found a solution how to permanently fix the problem in that working environment. In my new developing environment (new projects and new workplace) the problem never happens.
This is what helped me... seemed to happen after Windows Server 2012 SP install...
https://connect.microsoft.com/VisualStudio/feedback/details/1123745/setsite-failed-for-package-microsoft-visualstudio-editor-implementation-editorpackage
devenv /clearcache
devenv /updateconfiguration
In that case you can start Visual Studio setup again and choose the option showing two options, Repair and Uninstall. Then click Repair and when repair is done, restart the computer. Then the issue has been resolved.

What causes Visual Studio to reload projects?

Our team has a solution that has 15 projects that we all work on collaboratively using git for source control. Sometimes when switching branches Visual Studio simply updates the source files and the branch switch takes seconds(bounded by how fast I can type commands).
Other times though, when switching branches, Visual Studio will popup a dialog saying that it needs to reload all the projects and then I have to sit and wait for approximately five minutes while Visual Studio goes through this process.
I'm guessing that something we're doing with line endings is causing us to touch one of the Visual Studio specific files, and that causes the reload, only I'm not sure which one, or if that's even the right path to go down.
So my specific question then is, "What causes Visual Studio to need to reload projects?"
In fact it is quite easy:
Every file change will cause Visual Studio to reload the file, whether it has really changed, or not.
When changing a project file, it will reload the entire project.
Maybe git, or some other software, is updating some attributes of the file (so not the content). This might trigger the 'Visual Studio' file change monitor already. I have the same issue using TortoiseSVN.

How to disable visual basic errors in the error list in visual studio

I have a large solution which contains a mixture of C# and VB.Net projects.
If I get compilation errors because a project which several other projects depend upon fails to build, it is very hard to see the actual error(s) because of the number of VB errors in the error list window in Visual Studio. C# errors found in the projects I compiled show in the error list, but all VB errors appear (including in those projects I have not just compiled).
Is there any way of turning off this behaviour so that VB errors only appear for projects that I have explicitly compiled?
(I'm using Visual Studio 2008 if that makes a difference).
Unload all the projects other than the one you're interested in. When that's building, reload the projects one by one and fix their problems. To unload a project, right-click in Solution Explorer and pick "Unload project". This won't remove it from the solution, just unload it - and only for you (not other users) IIRC.
Obviously this means the "lowest" dependency (the most common code) needs to be fixed first.
Alternatively, click on "Project" in the error list to sort by project, and then just look at the errors in the project you're interested in.

Categories

Resources