Problem with missing assembly reference when using Visual Studio Code editor

I am developing Unity game apps on a PC using C#, running Visual Studio Code as the editor. The apps are targeted at PC and Android. Multiplayer uses Photon Pun 2.

The Unity version is 2019.3.14F1 - I know there are later, but I don't want to move forward just yet in case of 'unexpected problems'.

The VS Code version was 1.48.3 - and everything was fine - no compile errors, all code working OK etc.

Stupidly, I took Microsoft's advice to update VS Code, and its version went to 1.50.1. The instant result of this is that there are all sorts of compilation errors showing up in VS Code relating to my multiplayer code interfacing with Photon. All these errors stem back to the '
using Photon.Pun;
' lines in each file. The error says "the type or namespace name 'Pun' does not exist in the namespace 'Photon' (are you missing an assembly reference?)".

The code however is just as it was - it does not come up with any compile errors in the Unity editor itself, and it all runs fine, including the networking Photon parts. The problem is VS Code thinking there are errors.

I realise this is almost certainly as VS Code related problem, not Photon, but Photon.Pun is the only bit it objects to. I am not very familiar with the workings of VS Code, but I assume it must be reading the Unity project file to do intellisense etc. I am wondering if anyone has met this before and knows how to fix it?

(This is why I do not want to move from Unity 2019.3.14F1 to 2020.whatever at the moment - you never know what might happen).

Best Answer

  • nmw01223nmw01223
    Accepted Answer
    Tried rebuilding project files, swapping to a different editor (VS Community Edition 2019 - that was fine), but no difference - VSC persisted with the errors. Rest of intellisense working OK.

    In the end, totally uninstalled VSC and reinstalled, and that sorted it out. No idea what the actual fault was.

Answers

  • nmw01223nmw01223
    Accepted Answer
    Tried rebuilding project files, swapping to a different editor (VS Community Edition 2019 - that was fine), but no difference - VSC persisted with the errors. Rest of intellisense working OK.

    In the end, totally uninstalled VSC and reinstalled, and that sorted it out. No idea what the actual fault was.
  • I was wrong.

    To-day, the errors are back.

    The reason appears to be that in the process of trying to sort this, I installed VS Community Edition 2019 to see if that worked OK (it did). Then went back to VSC, and - that was fine too. Later I uninstalled VS Community Edition 2019 (it is taking about 4GB). It was uninstalling that which brought the errors back into VSC. Reinstalled VS Community Edition 2019, and it is all fine again.

    So, VS Community Edition 2019 installs something that VSC needs - but I haven't yet figured out what it is.
  • UPDATE:

    Gave up. Never managed to find out what VSC wanted and wasn't getting. Instead, reinstalled old version of VSC (1.48.2 from code.visualstudio.com/updates) and it is all fine again.
  • Me too. Exactly the same problem. Switched to Visual Studio 2019, which sees everything in the Photon namespace flawlessly. IMO this is a bug in vscode. After all, if the compiler doesn't have problem, the IDE shouldn't have a problem. Right?
  • nmw01223nmw01223
    edited January 13
    Further update:

    It suddenly went wrong again with the old VS code version (1.48.2). No reason, nothing changed, it just did.

    Does anyone have a clue what is going on here? I really don't want VS2019 installed if I don't need it - wastes about 4GB.

    Since the old VSC version 1.48.2 does not solve the problem, back with the latest - 1.52.1. Makes no difference.
  • There were issues with Unity at some point, which didn't create the project files properly. It could be that Unity isn't playing nice with VS/VS code in this version.
  • Thanks, yes, I'd read that, but I think it was earlier versions. This only seems to affect Photon code though.

    Any suggestion as to how I get around it?
Sign In or Register to comment.