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

  • nmw01223
    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.


  • nmw01223
    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.

    Gave up. Never managed to find out what VSC wanted and wasn't getting. Instead, reinstalled old version of VSC (1.48.2 from 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?
  • nmw01223
    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?
  • BUMP... Still waiting for an answer to this issue.
  • nmw01223
    edited March 11
    Possibly found an answer to this:

    Downgraded the C# for Visual Studio Code (Omnisharp) from the current (1.23.9) to 1.23.0. Compilation errors seem to have disappeared - at the moment anyway, don't know yet what else might have happened .... . Suggestion came from this -

    However, 1.23.1 replaced 1.23.0 about 6 months ago, and about 6 months ago was when it first all went wrong. I was wrong to say it only affected Photon code, there were some other bits also.

    Here's hoping.
  • artsiom
    edited March 14
    same issue with unity 2020.2.7f1 + photon 2.28.3 + visual studio 2019 Version 16.9.1

    - All imported Photon projects listed in References
    - Photon3Unity3D(dll library) also listed in References
    - Photon3Unity3D(dll library) added as existed item to the project
    Tried to mix options above in all possible variants. Still no luck.

    What is the correct way to import Photon into the project?

    As I see I have to just add PhotonUnity3D.sll to the References and thats it, this is what actually
    Unity does during importing Photon Library.

    The only way works for me - directly import each necesary "cs" file from Photon "Code" folder to my project.
    But this is the worst solution. Does anybody solved the issue?
  • Honestly, this sounds like a terrible issue in 2020.2.7 with VS 2019. Is the LTS version of Unity 2020 maybe better?

    You could also try this solution, which was suggested in different context by DRRosen3:
    The solution offered by the community was to uninstall the Visual Studio Editor package from the Unity Package Manager. This did indeed solve the issue of the multiple instances of VS being opened. When I reinstalled the VSE package, it got rid of this 'Pun' namespace error.

  • nmw01223
    edited March 16
    With Unity 2019.3.14F1, Visual studio code 1.52.1, C# for Visual Studio 1.23.0 (Omnisharp) the problem has not so far reappeared. Intellisense, syntax checking etc is all OK, and debugging works.

    What made the difference was reverting the version of Omnisharp C# for Visual Studio.

    Not sure if this means a problem with Omnisharp or not. It might be, or it might be that the add in has tightened up how it does something, and Unity has fallen foul of it.

    There is some information in the github Omnisharp issues list here which may be relevant - Specifically:

    "The problem is that the new .NET Core 3.1 SDK isn't supported by any current Mono release, so the setting "omnisharp.useGlobalMono" has been changed to "never" in 1.23.1 (see changelog This however is incompatible with Mono-based development e.g. Unity.

    You can change it back yourself to "omnisharp.useGlobalMono": "always" which should fix your scenario."

    The setting can be found in VSC: go to File > Preferences > Settings > Extensions > C# Configuration. Then change "Omnisharp: Use Global Mono". I haven't tried it as 1.23.0 is working for me, but I guess the thing to do is reload the latest (currently 1.23.9), and set that setting and see what happens.
  • @Tobias omg, its a magic!! Reinstalling VSE package solved my issue. Now everything works fine. Thanks a lot.
    Where is the original DRRosen3 post? Could u link it here?
  • Tobias
    Tobias admin
    edited March 16
    This is the original post I was referring to.
    Great to know it worked!