Search Unity

Visual Code finds ambiguity when they aren't there

Discussion in 'Scripting' started by LilGames, Jun 20, 2019.

  1. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    Hopefully this is the appropriate place to find help with this problem I've had every since I upgraded PC:

    I use Visual Code as my script editor. Have done for several years now. I used to run Windows 7 on an older PC, and Unity 5.x, 2017.x ... Then in November 2018 I upgraded the entire PC, OS is now Windows 10, and I have Unity 5.x, 2017.x, 2018.x installed, mostly using 2017 and 2018 since. And I keep Visual Code updated.

    Here is the problem: Visual Code keeps reporting "Ambiguity between MYCLASS and MYCLASS". Basically identical classnames, but the problem is NOT that there are identical class names in different scripts or conflicting namespaces. No, the problem is it thinks there are two editors open when in fact only one instance is open, and the conflict it reports is basically with "itself". My only recourse is to close VC and re-open it by clicking a script in my Unity project. The error goes away until later VC decides the currently open script file is again conflicting with itself.

    Never had this problem before on the old computer, so it's quite difficult to nail down where the blame lies (a configuration in VC? A configuration in Unity? A Windows 10 issue?) ...

    Googling has been no help as the posts I've found ended up being people with ACTUAL namespace conflicts. A few Unity Answers questions seem to report what I am experiencing, but of course those have no answers.

    Crossing my fingers and hoping someone has some insight. I love using VC as it's small, compact, and does what it needs to without the bloat of the full Visual Studio IDE.
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    MAYBE this might occur due to unity assembly cache if cached assemblies are still loaded along with your class, but I have no idea on how to fix that. Do you have any assembly definitions in your project?
     
    Owen-Reynolds likes this.
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @LilGames

    I guess you are talking about Visual Studio Code?

    I think I have the same problem occasionally (not 100% sure as I can't remember exact error message given by Visual Studio Code).

    Try renaming your class, and also the file this class is contained in. Then wait for Unity to compile the script, and go back to VS Code and the error should be gone.

    I'm not sure exactly what is causing this error, but for me this has removed the error message every time.

    Edit:
    IIRC I get this error usually after creating a new class, after I have opened it in VS Code.
     
  4. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    I was waiting for it to happen again so i could snap a screenshot... Here I had "Pathfinder.cs" already open in VS Code... A while later I double-click an error in Unity Console. That opened "SceneLoader.cs" in VS Code, but the file that was already open and part of the same project goes into this mode where it finds Ambiguity between itself and itself!

    upload_2019-6-21_13-14-29.png

    If I close "Pathfinder.cs", VSC still sees a problem:

    upload_2019-6-21_13-14-40.png

    The only solution at this point is to close VSC entirely and re-open it from Unity (double-click a script file or an error in the console) and then no errors are shown. Needless to say, this gets annoying.

    And no, this is not a namespace issue. It is not an issue affecting only certain files. It eventually happens to any script file and happens in other projects as well. Didn't happen before on my older computer.
     
    Last edited: Jun 21, 2019
  5. s1nc1tycyph3r

    s1nc1tycyph3r

    Joined:
    Aug 12, 2017
    Posts:
    3
    Ive recently run into the same Ambiguity issue when developing for unity! this is extremely frustrating because about a week ago vs code decided to remove all the code from my networkapi class i wrote for a game im developing for a client this happens frequently with vs code and most of the time i'm able to recover the data by copying all the code in the active editor in vs code(it won't let me save it for whatever reason) then opening the C# script location in explorer and the C# script in notepad++ then paste and save it from there and close it out in the active vs code editor! (that issue is another one ive frequently encountered in VS Code) but more frequently ever since a couple weeks ago ive been getting the Ambiguity error LilGames is describing. i know its not a namespace conflict because the code compiles just fine, and when i close vs code then reopen it from unity the error isnt there anymore however the minute i edit my script again it reappears for virtually most if not all of my class methods, and or properties.

    The Developers Of VS Code Really need to address and fix these issues for us Seasoned Programmers As It Makes it very difficult to work efficiently!
    I Hate the fact that there is still no known way to resolve these issues and virtually no forum posts that address these issues that are actually having posts to address the issues. all the ones ive found are total bs, with either the posts completely dismissing the issues altogether or posting about something completely irrelevant!
    anyways hopefully someone will find a solution and post it here, as will i if i find one!
     
    LilGames likes this.
  6. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,998
    Yes. I've had this happen several times with VC-code, I think after some oddball crash. The fix was always to delete a pile of auto-generated C-sharp files. I didn't take very good notes. Pasting from a stackExchange answer:

    "These are the files extensions to delete:
    • .csproj
    • .user
    • .sln"
     
  7. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    570
    Just to summarize to everyone, I just close VC and open the script again via Unity ("edit script") and everything is fine. So what appears to be happening is some sort of loss of context (to put it in very un-programmer-like terms). It's very annoying and didn't happen when i was on Windows 7. But I mention this so no one goes through the bother of deleting files before trying a simple "turn if off and on again".