question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JsonSerializationException when receiving a message from server in WebGL export

See original GitHub issue

When exporting my Unity project as a WebGL application, the following exception is thrown during runtime:

JsonSerializationException: Unable to deserialize instance of MyMessage because there is no parameterless constructor is defined on type.

This prevents any data sent by the server through messages to be deserialized and used on the client, which is a major problem.

After investigating on the issue with my local fork, I found that it originates from the TryGetConstructor method, at line 200:

if (AotRuntime || type.IsAbstract || type.IsInterface)
	return false;

It seems that AotRuntime is set to true for WebGL and iOS platforms, as shown in line 43 of the same file.

#if ((UNITY_WEBGL || UNITY_IOS || ENABLE_IL2CPP) && !UNITY_EDITOR)
			AotRuntime = true;
#else

I don’t really know what this parameter corresponds to, but it seems to cause the issue I describe here. My quick and dirty fix was to comment the AotRuntime part of the condition at line 200, but I can’t tell if it was there for a reason in the first place. What should be done to fix this?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
deniszykovcommented, Jan 21, 2023

Yep it is a bug, AotRuntime check should be few lines down. I will make PR.

0reactions
endelcommented, Jan 24, 2023

Thanks to @deniszykov’s PR (https://github.com/colyseus/colyseus-unity-sdk/pull/210) this has been finally fixed on latest version (0.14.21)

Read more comments on GitHub >

github_iconTop Results From Across the Web

POST JSON method does not work when project has been ...
However when I export the exact same project to WEBGL and upload it to my firebase hosting server, the JSON call does not...
Read more >
Unity WebGL with 3rd part APIs
The project was working perfectly with my local tests (accessing local JSON files), but when they sent the final API host address I...
Read more >
Get the website url which is displaying the unity WebGL ...
I have a WebGL Component which is hosted on a X server whose lets say "http://abc.com/webgl/mywebgl.html" is the unityWebGl source url.
Read more >
How to Send Data to Unity WebGL from Javascript or PHP
Unity Manual, Interacting with Browser Scripting https://docs.unity3d.com/Manual/ webgl -interactingwithbrowserscripting.html How to create a ...
Read more >
JSON .NET for Unity | Page 12
I'm having an issue serializing a 2d array. Just following the example on the Json.net website string[,] famousCouples = new string[,]
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found