using PhotonNetwork.ConnectUsingSettings(); do not connect and gives error in unity WebGl browser.

(unity version 2019.3.5 , Pun 2 . version 2.28.)

Here is the start function that im using to connect.

void Start()
{
PhotonNetwork.GameVersion = "1.0";
PhotonNetwork.ConnectUsingSettings();
}

it works fine in unity editor but not in the browser. i have my domain and hosting, The scene loads fine but when the PhotonNetwork.ConnectUsingSettings(); called it gives following error

[style color="Red"] Connect() failed to create a IPhotonSocket instance for WebSocketSecure. SocketImplementationConfig: {Udp=ExitGames.Client.Photon.SocketUdp, Tcp=ExitGames.Client.Photon.SocketTcp, WebSocket=ExitGames.Client.Photon.SocketWebTcp, WebSocketSecure=ExitGames.Client.Photon.SocketWebTcp} Exception: System.MissingMethodException: Constructor on type 'ExitGames.Client.Photon.SocketWebTcp' not found.
at System.RuntimeType.CreateInstanceImpl (System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, System.Object[] args, System.Globalization.CultureInfo culture, System.Object[] activationAttributes, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0
(Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
[style]

This is the PhotonServerSettings.

[img]file:///C:/Users/Welcome/Documents/photonserversettings.PNG[/img]

i've tried different solutions, There was a fix on website but this is already implemented in this version of PUN2.
file:///C:/Users/Welcome/Documents/fix.PNG

Help me solving this problem, Thanks

Comments

  • Tobias
    Tobias admin
    The SocketWebTcp should be in the project. It seems the code stripping of Unity is dropping the constructor on build, so this fails.

    Put a `[Preserve]` attribute on the class and the constructor.
    Or use the link.xml to make sure the code stripping does not drop anything in this class.

    It might be related to the version of Unity, which you are using. You should update to a recent LTS version and use latest PUN 2.
  • There are an option in Unity who cut code for optimization the Managed Stripping Level. I changed that for Low and worked for me.

    Also put this in link.xml:

    <assembly fullname="PhotonWebSocket">
    <type fullname="ExitGames.Client.Photon.SocketWebTcp" preserve="all"/>
    </assembly>
    <assembly fullname="PhotonWebSocket">
    <type fullname="ExitGames.Client.Photon.SocketWebSecure" preserve="all"/>
    </assembly>

    I hope that helps!
  • Tobias
    Tobias admin
    Thanks for the update. Yes, the link.xml is also an option.
    I didn't know the code stripping for WebGL is so aggressive. Will check our classes to counter that.
  • @AlexDev I have facing this problem, I tried your solution but it is not working and still giving me the same error
    Connect() failed to create a IPhotonSocket instance for WebSocket. SocketImplementationConfig: {Udp=ExitGames.Client.Photon.SocketUdp, Tcp=ExitGames.Client.Photon.SocketTcp, WebSocket=ExitGames.Client.Photon.SocketWebTcp, WebSocketSecure=ExitGames.Client.Photon.SocketWebTcp} Exception: System.MissingMethodException: Constructor on type 'ExitGames.Client.Photon.SocketWebTcp' not found.
  • @SOT, set up a link.xml, which will preserve ExitGames.Client.Photon. The SocketWebTcp is also a file in your project, where you could add the attribute Preserve.
  • @Tobias Thank you. Its just work perfectly for me.