Photon .Net SDK starting up

I am trying to set up a c# project using Photon realtime .Net SDK.

I am following the steps here.

https://doc.photonengine.com/en-us/realtime/current/getting-started/project-setup

Upon extracting the archive I cannot follow these instructions.

"Afterwards we navigate to our previously extracted .NET Realtime SDK archive and go into /libs/Debug/, select all Photon3DotNet files and copy them into a Libs directory (you have to create this one) in our .NET project"

There are no Photon3DotNeyt files found there. There are instead 3 folders.

What is the next step?

Comments

  • Tried to muddle through adding a reference to /net35/Photon-DotNet.dll did not work. Trying to build the simple example I receive "Exception thrown: 'System.DllNotFoundException' in mscorlib.dll"

    IS this being actively supported? The forum looks dead.
  • The Dll Not found error listed above, appears when I try to instantiate an object from the MyClient class in the example.
  • this.loadBalancingClient = new LoadBalancingClient();

    This line in the example code seems to be the spot where the 'System.DllNotFoundException' in mscorlib.dll" is created.
  • So to recap. Upon trying to instantiate a client:

    MyClient client = new MyClient();

    and executing this in the class constructor:

    loadBalancingClient = new LoadBalancingClient();

    I receive the following in Output

    'ChipZ2.exe' (CLR v4.0.30319: ChipZ2.exe): Loaded 'C:\Users\xxxxx\Documents\Visual Studio 2017\Projects\ChipZ2\ChipZ2\bin\Debug\Photon-DotNet.dll'. Symbols loaded.
    Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
    Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
    Exception thrown: 'System.DllNotFoundException' in mscorlib.dll
  • Chasing the Dll Not found exception further down the rabbit hole , it occurs on:

    this.LoadBalancingPeer = new LoadBalancingPeer(this, protocol);

    in LoadBalancingCLient.cs
  • Lastly I get to:


    private readonly Pool<Dictionary<byte, object>> paramDictionaryPool = new Pool<Dictionary<byte, object>>(() => new Dictionary<byte, object>(), x => x.Clear(), 1); // used in OpRaiseEvent() (avoids lots of new Dictionary() calls)

    Attempting to step into this asks for a SupportClass.cs which is not supplied with the package.
  • (Incidentally, one must comment out the section as shown to allow the project to build.
    [Conditional("UNITY_XBOXONE")]
            private void CheckConnectSetupXboxOne()
            {
            }
            /*
                this.AuthMode = AuthModeOption.Auth;
                if (this.AuthValues == null)
                {
                    UnityEngine.Debug.LogError("UNITY_XBOXONE builds must set AuthValues. Set this before calling any Connect method. Refer to the online docs for guidance.");
                    throw new Exception("UNITY_XBOXONE builds must set AuthValues.");
                }
                if (this.AuthValues.AuthPostData == null)
                {
                    UnityEngine.Debug.LogError("UNITY_XBOXONE builds must use Photon's XBox Authentication and set the XSTS token by calling: PhotonNetwork.AuthValues.SetAuthPostData(xstsToken). Refer to the online docs for guidance.");
                    throw new Exception("UNITY_XBOXONE builds must use Photon's XBox Authentication.");
                }
                if (this.AuthValues.AuthType != CustomAuthenticationType.Xbox)
                {
                    UnityEngine.Debug.LogWarning("UNITY_XBOXONE builds must use AuthValues.AuthType \"CustomAuthenticationType.Xbox\". PUN sets this value now. Refer to the online docs to avoid this warning.");
                    this.AuthValues.AuthType = CustomAuthenticationType.Xbox;
                }
                if (this.LoadBalancingPeer.TransportProtocol != ConnectionProtocol.WebSocketSecure)
                {
                    UnityEngine.Debug.LogWarning("UNITY_XBOXONE builds must use WSS (Secure WebSockets) as Transport Protocol. Changing the protocol now.");
                    this.LoadBalancingPeer.TransportProtocol = ConnectionProtocol.WebSocketSecure;
                }
    
                this.EnableProtocolFallback = false; // no fallback on Xbox One
            }*/
    
  • I am sorry to see you have to go though all the hoops to get this going.
    It's annoying that the Conditional attribute does not help avoid the code to compile. I assume the compile define is not set? So I added proper #if conditions for the next release.

    Which package do you use, by the way? The Photon C# SDK from our page? And you build for which platform and with which .Net SDK?
  • I am using the Photon Realtime, .Net SDK found here:

    https://www.photonengine.com/en-us/sdks#sdkrealtimenet

    As mentioned, I am trying to follow the instructions listed here:

    https://doc.photonengine.com/en-us/realtime/current/getting-started/project-setup

    But they do not match the current release. I am doing something wrong because as soon as I try to instantiate a MyClient object from the code here:
    using System.Collections.Generic;
    using Photon.Realtime;
    
    public class MyClient : IConnectionCallbacks
    {
        private LoadBalancingClient loadBalancingClient;
    
        public MyClient()
        {
            this.loadBalancingClient = new LoadBalancingClient();
            this.SubscribeToCallbacks();
        }
    
        ~MyClient()
        {
            this.UnsubscribeFromCallbacks();
        }
    
        private void SubscribeToCallbacks()
        {
            this.loadBalancingClient.AddCallbackTarget(this);
        }
    
        private void UnsubscribeFromCallbacks()
        {
            this.loadBalancingClient.RemoveCallbackTarget(this);
        }
    
        // call this to connect to Photon
        public void Connect()
        {
            this.loadBalancingClient.AppId = "<your appid>";  // set your app id here
            this.loadBalancingClient.AppVersion = "1.0";  // set your app version here
    
            // "eu" is the European region's token
            if (!this.loadBalancingClient.ConnectToRegionMaster("eu")) // can return false for errors
            {
                // log error
            }
        }
    
        void IConnectionCallbacks.OnConnectedToMaster()
        {
            // client is now connected to Photon Master Server and ready to create or join rooms
        }
    
        // [...]
    

    I get a dll not found error as given above.
  • I am building for Windows 64 bit. I can target any .Net framework version (I tried 3.5 and the latest). Visual Studio 2017.
  • Any help getting this running?
  • Spektre
    Spektre
    edited December 2020
    Tobias wrote: »
    I am sorry to see you have to go though all the hoops to get this going.
    It's annoying that the Conditional attribute does not help avoid the code to compile. I assume the compile define is not set? So I added proper #if conditions for the next release.

    Which package do you use, by the way? The Photon C# SDK from our page? And you build for which platform and with which .Net SDK?

    John helped out below.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited December 2020
    Posting the solution from Discord here:

    step1: fix error caused by leftover UNITY related code references, in LoadBalancingClient.cs (add #if wrappers or comment out lines in CheckConnectSetupWebGl and CheckConnectSetupXboxOne)
    [Conditional("UNITY_WEBGL")]
            private void CheckConnectSetupWebGl()
            {
                #if UNITY_WEBGL
                if (this.LoadBalancingPeer.TransportProtocol != ConnectionProtocol.WebSocket && this.LoadBalancingPeer.TransportProtocol != ConnectionProtocol.WebSocketSecure)
                {
                    this.DebugReturn(DebugLevel.WARNING, "WebGL requires WebSockets. Switching TransportProtocol to WebSocketSecure.");
                    this.LoadBalancingPeer.TransportProtocol = ConnectionProtocol.WebSocketSecure;
                }
    
                this.EnableProtocolFallback = false; // no fallback on WebGL
                #endif
            }
    
            [Conditional("UNITY_XBOXONE")]
            private void CheckConnectSetupXboxOne()
            {
                #if UNITY_XBOXONE
                this.AuthMode = AuthModeOption.Auth;
                if (this.AuthValues == null)
                {
                    UnityEngine.Debug.LogError("UNITY_XBOXONE builds must set AuthValues. Set this before calling any Connect method. Refer to the online docs for guidance.");
                    throw new Exception("UNITY_XBOXONE builds must set AuthValues.");
                }
                if (this.AuthValues.AuthPostData == null)
                {
                    UnityEngine.Debug.LogError("UNITY_XBOXONE builds must use Photon's XBox Authentication and set the XSTS token by calling: PhotonNetwork.AuthValues.SetAuthPostData(xstsToken). Refer to the online docs for guidance.");
                    throw new Exception("UNITY_XBOXONE builds must use Photon's XBox Authentication.");
                }
                if (this.AuthValues.AuthType != CustomAuthenticationType.Xbox)
                {
                    UnityEngine.Debug.LogWarning("UNITY_XBOXONE builds must use AuthValues.AuthType \"CustomAuthenticationType.Xbox\". PUN sets this value now. Refer to the online docs to avoid this warning.");
                    this.AuthValues.AuthType = CustomAuthenticationType.Xbox;
                }
                if (this.LoadBalancingPeer.TransportProtocol != ConnectionProtocol.WebSocketSecure)
                {
                    UnityEngine.Debug.LogWarning("UNITY_XBOXONE builds must use WSS (Secure WebSockets) as Transport Protocol. Changing the protocol now.");
                    this.LoadBalancingPeer.TransportProtocol = ConnectionProtocol.WebSocketSecure;
                }
    
                this.EnableProtocolFallback = false; // no fallback on Xbox One
                #endif
            }
    

    step2: fix DLL build output filename: renamed "libs\Debug\Photon-NetStandard.*" to "libs\Debug\Photon-DotNet.*", mainly .dll file (you could also do the same for "libs\Release"

    build solution. it should work I just tested it.
  • Spektre
    Spektre
    edited December 2020
    Thanks John, but no joy here.

    Walking step by step through the instructions listed here:
    Preparation
    The first step you have to do is to download the .NET Realtime SDK. You can do this on the SDKs download page or by following this direct link. Note: downloading any SDK requires you to be signed in. If you haven't created an account yet, please do this before, you will need it anyway.

    After downloading the SDK, you can extract the archive's content. This SDK already includes a Visual Studio solution and some example projects, which you can take a look at, too. Furthermore the SDK contains the necessary libraries and the LoadbalancingAPI. We will need both folders and their included files later.

    Done.
    Creating And Setting Up The Visual Studio Project
    Next we want to set up our own Visual Studio project and start working with Photon. To do so, we start Visual Studio (in our example we are using Visual Studio 2017) and create a new project under File/New/Project.... This opens up the New Project dialog where we select Console App (.NET Framework) under Visual C#. This will create a new solution with an almost empty project.

    Done, except that I am building a Windows Forms App
    Afterwards we navigate to our previously extracted .NET Realtime SDK archive and go into /libs/Debug/, select all Photon3DotNet files and copy them into a Libs directory (you have to create this one) in our .NET project.

    These do not exist. Precisely which files/folders should be copied?
    Back in Visual Studio we right-click on References in our project and select Add Reference.... A new dialog opens up where we click on the Browse button, navigate first to our solution and project folder and then into the newly created Libs folder. In this folder we select the Photon3DotNet.dll and click on the Add button. We can close the Reference Manager window by clicking OK. You will notice that this step has added Photon3DotNet to the project's references.

    Again, this dll does not exist. Which file specifically gets a reference added. (I did try adding a reference to the renames NetStandard.dll and it is missing the IConnectionCallbacks interface. The original "libs/Debug/net35/Photon_DotNey.dll seems to include the reference.
    Next we want to add a new folder to the project. We therefore right-click on our project in the Solution Explorer and select Add/New Folder. This will create a new folder in our project, which we name LoadbalancingAPI. Now we right-click on that new folder and select Add/Existing Item.... In the new dialog we navigate to our extracted archive again and select all .cs files in the PhotonLoadbalancingApi folder and click on the Add button. This will copy the selected files to the new LoadbalancingAPI folder in our project.

    Done

    A new class is made named MyClient from the example code provided.
    using System.Collections.Generic;
    using Photon.Realtime;
    
    public class MyClient : IConnectionCallbacks
    {
        private LoadBalancingClient loadBalancingClient;
    
        public MyClient()
        {
            this.loadBalancingClient = new LoadBalancingClient();
            this.SubscribeToCallbacks();
        }
    
        ~MyClient()
        {
            this.UnsubscribeFromCallbacks();
        }
    
        private void SubscribeToCallbacks()
        {
            this.loadBalancingClient.AddCallbackTarget(this);
        }
    
        private void UnsubscribeFromCallbacks()
        {
            this.loadBalancingClient.RemoveCallbackTarget(this);
        }
    
        // call this to connect to Photon
        public void Connect()
        {
            this.loadBalancingClient.AppId = "<your appid>";  // set your app id here
            this.loadBalancingClient.AppVersion = "1.0";  // set your app version here
    
            // "eu" is the European region's token
            if (!this.loadBalancingClient.ConnectToRegionMaster("eu")) // can return false for errors
            {
                // log error
            }
        }
    
        void IConnectionCallbacks.OnConnectedToMaster()
        {
            // client is now connected to Photon Master Server and ready to create or join rooms
        }
    

    With the file renamed, now when I attempt to run and instantiate a new MyClient object I get
    "Exception thrown: 'System.IO.FileNotFoundException' in Chipz.exe
    An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Chipz.exe
    Could not load file or assembly 'Photon-NetStandard, Version=4.1.4.4, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified."



  • Does it need named one thing for reference sake and another thing for another sake?
  • OK< that seems to allow the project to run. The file you referenced above needs to be renamed to be used as the reference in the VS project, but the .dll file NOT renamed must exist in the project's /bin/Debug folder.

    Very strange.
  • Vygar
    Vygar
    edited December 2020
    I'm experiencing similar issues with just getting the server running. In my case, the server appears to "start" but from PhotonControl but when trying to start the LoadBalancing service, it errors with a System.ComponentModel.Win32Exceptions - File not found error which is odd as I am running the 64bit version of the software.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @Vygar,

    Thank you for choosing Photon!

    Your issue is different as it's about starting the Photon Server and not the Photon .NET client SDK.
    You can search the right category or post something there.
    If you are using Photon Server v5 you need a license.
    Make sure to share server logs if you are going to start a new discussion.