- Home /
The question is answered, right answer was accepted
Namespace references keep breaking in Visual Studio
Since updating Unity from 2019.2 to 2019.3, I am unable to compile the 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, 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.
The assemblies are Assembly-CSharp, Assembly-CSharp-Editor, Assembly-CSharp-Editor-firstpass and Assembly-CSharp-firstpass. The normal ones that get created as far as I know.
Why does the reference break each time I restart VS? (Edit: and sometimes when rebuilding the solution without restarting)
Versions
Unity 2019.3.12f1 Personal.Visual Studio Community 2017 15.9.22.
I've tried:
all of these https://stackoverflow.com/questions/450999/are-you-missing-an-assembly-reference-compile-error-visual-studio
All of these http://www.codeandyou.com/2017/08/missing-assembly-reference-in-visual.html
- 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:
From more testing I found that now and then (don't know what triggers it) the reference will break without closing Visual StudioBump. Any ideas on how to possibly fix this would be appreciated
Bump. Still no solution found. I've deleted a lot of the project but the errors just come up from different scripts. Definitely some issue with VS
Answer by IINovaII · May 13, 2020 at 08:15 AM
It's a bug that happens in Unity 2019.3.12f. Try the newer Unity version 2019.3.13 instead. It's been fixed there. - Nova
Wow. I hit check for updates in the editor and it told me there were none... But found it in the hub. Downloading it now
If I had a million dollars I'd give it to you. I spent 8+ hours trying to figure this out thinking Unity was up to date... It's working now
Answer by luixodev · Sep 05, 2020 at 10:24 AM
Same here when I update to Unity 2020.1.4f.4412, any idea?
Close VS, then create a new c# file inside unity, double click the file, then all namespaces were restored.
hey, yeah it works always but my problem is that the problem always occurs again and again randomly
Answer by metixgosu · Apr 08, 2021 at 12:13 AM
Trigger is if you remove mononehaviour if from any script what is attached on game object in unity, if you want remove mono for any reason in vs just remove it from game object first
Answer by HyronXIII · Sep 01, 2021 at 02:45 PM
Also closing VS and from the Editor clicking Assets -> Open C# Project worked for me, which I assume does something similar to the above mentioned creating a new C# script
Answer by zwang-steven · Oct 12, 2021 at 04:13 PM
Regenerate project files fixes the issue:
Go to Unity 【Edit】 → 【Preferences】 → 【External Tools】 → Click the 【Regenerate project files】 button under "Generate .csproj files for:" → Back to VS
Follow this Question
Related Questions
Visual Studio 2017 namespace cannot be found on installed package 1 Answer
Make visual Studio Ignore some folders for namespace refactoring 0 Answers
[resolved] Visual Studio does not find a namespace from the project 1 Answer
Async/Await in 2019.2 and Visual Studio 2019 1 Answer
Need help with namespace error 1 Answer