Search Unity

VS Code Error [SOLVED]

Discussion in 'Code Editors & IDEs' started by Nicokam, Aug 20, 2020.

  1. Nicokam

    Nicokam

    Joined:
    May 28, 2020
    Posts:
    64
    I suddenly got this warning today from VS Code of my Unity project I have been working for months making me unable to keep programming my c# scripts, because it no longer has autocompletes terms from Mono develop or any other c# words.

    upload_2020-8-20_16-27-21.png

    It has something to do with Omnisharp. I found some things online but nothing seamed to work and it is a very confusing subject I don't seem to get.

    Can someone help me with clear instructions please?
     
  2. pantang

    pantang

    Joined:
    Sep 1, 2016
    Posts:
    219
    Not to sure about that error the output might help but for your auto complete woes there should be a hidden folder called .vs in your project folder. delete it and reload the project normally fixes missing autocomplete problems. If its unity wide then you need to set the external editor to visual studio in your project settings.
     
  3. Nicokam

    Nicokam

    Joined:
    May 28, 2020
    Posts:
    64
    Erased the folder and restarted unity and it was not solved.

    Also did set Visual Studio Code as the external editor again, just to make sure. That's the weird thing, I did that a long time ago and it was working just fine. It stopped working all of a sudden.

    I think it's important to say I use a Mac

    Parts of the error:

    [fail]: OmniSharp.MSBuild.ProjectLoader
    The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

    [fail]: OmniSharp.MSBuild.ProjectManager
    Attempted to update project that is not loaded:
     
    NOT_A_ROBOT1101 likes this.
  4. Nicokam

    Nicokam

    Joined:
    May 28, 2020
    Posts:
    64
  5. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
    Yeah, I dealt with this quite a lot. VSCode is just a garbage IDE, It's the worst thing I've ever used.

    - Try deleting the .sln file in your project
    - (< Unity 2020.1) Try going into Preferences > External Editors > Generate all .csproj files
    - (>= Unity 2020.1) Try going into Preferences > External Editors > Should be a button called "Regenerate ..." or something similar, click it.
    - Open any script via double click

    Or
    - Revert C# extension to a previous version

    Or
    - Give up and switch to a new IDE if you don't have to use VSCode.
     
    aminhanifm, Aykutkaraca and Rneama like this.
  6. Nicokam

    Nicokam

    Joined:
    May 28, 2020
    Posts:
    64
    Thanks for the reply! Which IDE would you suggest?
     
  7. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
    I would love to know the answer to that question as well.

    I heard people praising Ryder, but it's quite expensive. It does have a free trial for a month, I might check it out.
    Stick to regular Visual Studio if you can though. VSCode is common because it's 100% free so all tech companies are going for it, but it's inexcusably unpolished.
     
    Nicokam likes this.
  8. Teos

    Teos

    Joined:
    Jul 30, 2015
    Posts:
    2
    I just received this same issue, did not make any difference deleting and regenerating those project files.
    It was only after I downgraded VSCode C# extension from 1.23.1 to 1.23.0 that it started to work again.
     
  9. A_Sloane

    A_Sloane

    Joined:
    Aug 19, 2015
    Posts:
    10
    Same that Theos. After 1 hour trying to figure out a solution, the easiest thing to do was to downgrade to 1.23.0.
     
    Nicokam and Kurt-Dekker like this.
  10. TorchFireGames

    TorchFireGames

    Joined:
    Mar 9, 2017
    Posts:
    7
    I ran into this problem too but got it worked out after jumping through some hoops. Like others here mentioned, it turned out to be an issue with Microsoft/OmniSharp's C# extension for VS Code.

    Here's the full set of steps I ran through to fix it:
    1. Close out Unity.
    2. Delete all the VS Project files in your Unity project folder (.csproj, .sln, .vscode folder).
    3. Open VS Code, hit Ctrl+Shift+P and type `Disable Auto Updating Extensions`. This will stop Microsoft from auto-updating C# to a broken version.
    4. Find the C# extension in the list of your installed VS Code extensions, right click, then click "Install Another Version".
    5. Select v1.23.0 and let it install.
    6. Close out of VS Code.
    7. Open your Unity project, and the VS Project files will automatically be rebuilt.
    8. VS Code and Intellisense back to normal again.
     
    Rughnar, Lorrak, Pandazole and 4 others like this.
  11. airespt

    airespt

    Joined:
    Apr 7, 2016
    Posts:
    2
    I had a new breakage with VSC on linux this week.
    One day all was fine, next day, suddenly, VSC complains about all refs to code placed inside Plugins folder.

    In my case it seems Omnisharp was skip/ignoring the Assembly-CSharp-firstpass.csproj file.
    Downgrading C# extension from 1.23.3 to 1.23.0 fixed it. Thank you all.

    (Beware, looks like MS is pushing .Net CORE so hard, they are breaking stuff left and right.)
     
    Lorrak likes this.
  12. cosmicelysium

    cosmicelysium

    Joined:
    Jul 20, 2015
    Posts:
    6
    omg thank you so much. I tried so many things and this finally fixed the issue :)

    EDIT: There seem to be plenty of logged issues with the extension:
    https://github.com/OmniSharp/omnisharp-vscode/issues
     
    Last edited: Oct 15, 2020
  13. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
    Thank you #TorchFireStudios and the rest, life savers you are! I clicked some update button without paying attention... boy, almost wasted a whole work day. MAN!

    Problem: Open VS Code, namespaces are screwed in a way that doesn't have much logic +1K errors with messages like .csproj files not found where they definitely are found.. all sorts of trouble that also seems to jump from on issue to another between restarts without much logic to it. In addition VS Code eats CPU time like a starved baboon on steroids, I mean on a scale from 0=working to 10=heroin-overdose we are at 9.9 nuclear catastrophy.
    Culprit: C# for Visual Studio Code 1.23.4 or .3 not even sure. This is the editor extension that understands C#.
    Fix: Downgrade option doesn't exist. 1. Uninstall, 2. download manually 1.23.0 VSIX file, 3. find "Install from VSIX" option, 4. Enjoy life again. Oh and 5. I also run "Extensions: Disable Auto Updating Extensions", figure that's necessary to avoid this in the future.
     
    Last edited: Oct 21, 2020
  14. NOT_A_ROBOT1101

    NOT_A_ROBOT1101

    Joined:
    Jun 18, 2020
    Posts:
    39
    Thanks, man! I struggled with this problem a lot and as it turns out, I forgot to do this.
     
    Nicokam likes this.
  15. stickygamessthlm

    stickygamessthlm

    Joined:
    Nov 12, 2020
    Posts:
    3
    Got this problem after updating Unity LTS. (Unity 2019.4.20f0 -> f1). The 1.23.0 downgrade solution didn't work for me though.

    After some more googling, came across this thread: https://forum.unity.com/threads/nam...space-unityengine-error-on-2019-3-2f1.831922/

    So I tried just changing the External Script Editor in Unity preferences to 'open by file extension', then closing both Unity and VSCode, then reopening and selecting VSCode again. Now it seems to work as it should with latest version of C# extension
     
    Lorrak and L_Bens_Up like this.
  16. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    967
    Downgrading to 1.23.0 solved the problem. Thanks a lot!
     
  17. TorchFireGames

    TorchFireGames

    Joined:
    Mar 9, 2017
    Posts:
    7
    Update for anyone else that runs across this problem...

    It turned out that this is a known compatibility issue between the C# extension in VS code, Mono/Omnisharp, and Unity. It's even listed prominently at the top of the C# extension's changelog:

    For Mono-based development (e.g. Unity) that requires full .NET framework, you need to set "omnisharp.useGlobalMono": "always". The current value of "auto" will remain "never" until Mono [URL='https://github.com/mono/mono/issues/20250']upgrades their bundled MSBuild version[/URL].


    So instead of downgrading to 1.23.0 (which also works but is outdated), you can instead just use their recommended solution:
    • In VS Code, open Settings
    • Search for "omnisharp use global"
    • Change Omnisharp: Use Global Mono setting to: "always"
    Then to make sure Unity recognizes the changes...
    • Close all Unity projects
    • Delete any .sln or .csproj files (Unity will recreate them)
    • Re-open a Unity project
    • Double click any script to have it open in VS code
    • Let the omnisharp compiler do its thing
    • Intellisense should now be working again
     
  18. tomaszminiewicz

    tomaszminiewicz

    Joined:
    Dec 30, 2021
    Posts:
    1
  19. Lorrak

    Lorrak

    Joined:
    Sep 17, 2019
    Posts:
    50
    this should be sticked somewhere in forum or thread created just for Vs code related problems :confused:
     
    xucian likes this.
  20. andycodes

    andycodes

    Joined:
    Jan 22, 2013
    Posts:
    39
    Today on Mac, with the C# plugin installed, latest VSCode Editor package installed in the package manager (v.1.2.5), and latest install of monodevelop installed on my machine, I only have `omnisharp.monoPath`, and no `omnisharp.useGlobalMono` setting. Am I missing a step, or has this setting been removed?

    There was another fix on the forums which was to set `omnisharp.useModernNet` to false. This worked for a moment, but whenever I reopen VSC, I'm given a popup saying that I need to have a full install of mono. If I go back to the omnisharp settings, check the use modern net box, restart the editor, and then turn it off again, suddenly I'm back in business. But frankly, this isn't something I should have to put up with every time I want to edit code in Unity.
    I love using VSC for almost everything, but when it comes to Unity it's been a constant sore spot for the 3 years I've tried using it off and on.
     
  21. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    Unity's interconnect package hasn't been supported for the past couple of years, and in the thread linked below announced they have no intention of trying to improve the situation.

    https://forum.unity.com/threads/update-on-the-visual-studio-code-package.1302621/
     
    Last edited: Dec 25, 2022
    andycodes likes this.
  22. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    Visual Studio struggles because Unity doesn't use it. Unity does not care about VS. It's just a code editor. It might as well be Notepad++ or Sublime. Unity doesn't care. Because of this, Unity blows away the .sln and .csproj files anytime it feels like it and then VS gets all confusticated and confused, for me on a near-daily basis.

    Thus it is necessary to keep this cribsheet handy so you can wipe Visual Studio's chin whenever it drools.

    This may help you with intellisense and possibly other Visual Studio integration problems:

    Most often the fix is as simple as doing Assets -> Open C# Project from Unity. Other times it requires more.

    Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

    Barring all that, move on to other ideas:

    https://forum.unity.com/threads/intellisense-not-working-with-visual-studio-fix.836599/

    Also, try update the VSCode package inside of Unity: Window -> Package Manager -> Search for Visual Studio Code Editor -> Press the Update button

    Also, this: https://forum.unity.com/threads/no-suggestions-in-vscode.955197/#post-6227874
     
    andycodes likes this.
  23. SharpC_

    SharpC_

    Joined:
    Apr 10, 2021
    Posts:
    2
    personally I don't like any JetBrain's IDEs, they are just too heavy
     
  24. KillDashNine

    KillDashNine

    Joined:
    Apr 19, 2020
    Posts:
    453
    Jetbrains any day. Microsoft's business model is based on selling bugfixes to their products.
     
    yuhuilalala and Lorrak like this.