When I open Visual Studio Code, I get two error for some of my classes inherited from MonoBehaviour and ScriptableObject:
cs0246: The type or namespace name could not be found
For a static class:
cs0103:The name ____ does not exist in the current context.
If I open files with these classes and save them again (just “ctrl + s”, nothing more), then the problems disappear. I can build the project even without resolving the problems. But if I close VS Code and open it again, I get these errors again.
All files are placed in the same folders as the files that do not arise any errors.
How can I fix it?
OS: Windows 10, 64bit
Visual Studio Code version: 1.41.1
C# extension version: 1.21.10 (C# for Visual Studio Code (powered by OmniSharp))
Unity version: 2019.3.0f6
Try the following steps:-
- Open Unity
- Open Package Manager Window
- Check the version of your visual studio code package
If you are use package version 1.1.4 use the following steps to resolve the error:-
- In Unity, go to Window/Package Manager
- Search for your Visual Studio Code Editor package
- Downgrade to version 1.1.3
- Close Unity
- Delete your .csproj and .sln files in your project
- Open Unity
- Reopen VS Code and the errors are gone
Today November 24th, 2020
I had the same issue with Unity 2019.4.13 (LTS) and Visual Studio Code Package (v 1.2.2)
Instead of downgrading to 1.1.3, there was an update for v 1.2.3
I followed the steps of upgrading the package, closing unity, deleting the sln and csproj, then openeing Unity and vscode and it WORKED!
Thanks a lot
OS : Ubuntu:20.04
VSCode : 1.51.1
Unity : 2019.4.15f1
Visual Studio Code Package : v1.2.3
I had the same problem, I didn’t downgrade the vscode package. Simply
- Close Unity
- Delete .sln and .csproj and close vscode
- Restart unity and regenerate project file by
External Tools →
Regenerate Project Files.
I’m on Unity 2019.4.11f1 and package 1.2.2 and randomly had issues today where only one csproj was working at a time, anything from other namespaces from other csproj files were not being recognised. I followed these steps, downgraded and deleted the .sln and now it’s working normally again. Thank you
I also go this in the past and I’m now on 2019.3.10f1 and still got it. However if you just run and stop your project in unity and make sure all errors are resolved, the missing class imports in vs code will be fixed.
Using Unity 2020.1.2f1 and VS Code 1.51 just follow those (@RahulRaman ) step, except downgrading change to upgrading to current version (1.2.3 on my case). It’s really work.
I’ve imported the “Nethereum” Unity plugin, in Unity 2021.x, and none of these solutions is working…