question

brandon@uprootstudios.com avatar image
brandon@uprootstudios.com asked

C# server SDK in Unity

Hi, we're trying to use the C# GSDK in Unity. We can call the GameserverSDK fine, however it fails when trying to deserialize the configuration file (either using SDK.Start() or SDK.getConfigSettings()).

Here is the error described:

Cannot read configuration file C:\PATH\gsdkConfig.json ---> Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Microsoft.Playfab.Gaming.GSDK.CSharp.JsonFileConfiguration+JsonSchema. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'heartbeatEndpoint', line 2, position 22.

We've tried using both JSON.NET.Unity3d and Newtonsoft.Json with a NuGet manager for Unity, however the issue seems to lie inside the SDK itself.

Has anyone had any experience with this issue?

Thanks!

apisunity3dsdks
15 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ravarna avatar image ravarna commented ·

@Brandon Phillips what's the nuget version of the C# GSDK that you are using?

0 Likes 0 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com commented ·

.

0 Likes 0 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com commented ·

@ravarna It is the latest version 0.9.190405, however I have also tested with 0.5 and 0.7 and the error still occurs.

0 Likes 0 ·
ravarna avatar image ravarna brandon@uprootstudios.com commented ·

That's weird. We don't have a Unity game in our test infrastructure but we have had multiple unity customers use the C# GSDK without encountering this issue. I will keep digging and let you know what we find.

0 Likes 0 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com ravarna commented ·

We tried using pure Json.NET in a blank project only calling SDK.getConfigSettings() and the same issue occurred which leads me to believe it is related to the SDK itself. Is it possible to override this method or override SDK.Start() and assign configuration values manually?

0 Likes 0 ·
Show more comments
brandon@uprootstudios.com avatar image brandon@uprootstudios.com commented ·

@ravarna

It's a blank Unity project. However, I just had a new development: It now seems to work fine when the scripting backend is set to Mono, and it seems the issue only exists when the scripting backend is IL2CPP. The issue persists in the two Unity versions I have tested (2019.1.1f1 and 2018.3.12f1). For now, this workaround is alright, but our actual client builds require IL2CPP, however we can look into switching scripting backends at buildtime if necessary.

@TCROC This is the issue we've been having, however our current solution is to only use the Mono backend as IL2CPP does not seem to be compatible with certain aspects of the C# GSDK (at least in Unity 2018.3 and 2019.1)

0 Likes 0 ·
Travis Lange avatar image Travis Lange brandon@uprootstudios.com commented ·

Hey @Brandon Phillips. Could you post your config file and the code you are using to try to deserialize it? That means the config file, the model you are attempting to deserialize into, and the actual deserialization code. That might be a lot so just attaching them as attachments would be fine.

0 Likes 0 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com Travis Lange commented ·

@TCROC The issue doesn't occur when deserializing the config file manually by using a self-written JsonSchema class. The issue only occurs when calling either GameserverSDK.Start() or GameserverSDK.getConfigSettings() and only when Unity's scripting backend is set to IL2CPP. When using Mono, the issue does not occur. Here is the gsdkConfig.json that the GSDK tries to read (and fails):

{
  "heartbeatEndpoint": "127.0.0.1:56001",
  "sessionHostId": "7163f019-1bf9-4108-9560-15b1d6c0440f",
  "vmId": "xcloudwusu4uyz5daouzl:WestUs:93a3e5f0-edd2-440d-80d3-68ee2dc3708c:tvmps_e9fb182660314356ba062ebf5fe472ae42ba82cc41ed4e5596734a1c56d5fb9c_d",
  "logFolder": "C:\\GameLogs\\",
  "certificateFolder": "C:\\GameCertificates",
  "sharedContentFolder": "C:\\GameSharedContent",
  "gamePorts": {
    "game_port": "56100"
  },
  "publicIpV4Address": "127.0.0.1",
  "fullyQualifiedDomainName": "localhost"
}
0 Likes 0 ·
Show more comments
brandon@uprootstudios.com avatar image brandon@uprootstudios.com commented ·
@ravarna

Unfortunately the issue is still prevalent, although the error is now slightly different:

Cannot read configuration file C:\Users\ManCavePC\Desktop\OUTPUTPLAYFAB\PlayFabVmAgentOutput\PATH\gsdkConfig.json ---> Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Microsoft.Playfab.Gaming.GSDK.CSharp.GsdkConfiguration. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'heartbeatEndpoint', line 2, position 22.

This issue still only appears when using IL2CPP.

0 Likes 0 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com brandon@uprootstudios.com commented ·

(For some reason I cannot edit the above comment)

Another issue is that with this latest GSDK, the server does not terminate when CurrentGameState becomes 'Terminating'. It appears the issue is with GameserverSDK.LogMessage()

Here is the (unchanged) code that worked with the previous GSDK:

static void OnShutdown() {
    Debug.Log ("Call to shut down!");
    GameserverSDK.LogMessage("Shutting down...");
    Application.Quit();
}

In the log, after "Call to shut down!" there are about 50 outputs from the stack trace after LogMessage() is called, and Application.Quit() is never run. I'll revert back to the previous 0.9 GSDK for now and keep using Mono.

0 Likes 0 ·
ravarna avatar image ravarna brandon@uprootstudios.com commented ·

Thanks for reporting the issue. We will look in to it. In case we want to iterate over GSDK changes with you (so that we can get the serialization sorted out), what's the best way to share an early drop of the dlls.

0 Likes 0 ·
Show more comments
Show more comments
jan-halamicek avatar image
jan-halamicek answered

Guys I am trying to make all of this work. I mean the Unity + Playfab Multiplayer. However when I run the MockVmAgent.exe from the powerShell I get this error:

MissingMethodException: Default constructor not found for type System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x0007b] in <c79628fadf574d3a8feae0871fad28ef>:0
at System.RuntimeType.CreateInstanceSlow (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00009] in <c79628fadf574d3a8feae0871fad28ef>:0
at System.RuntimeType.CreateInstanceDefaultCtor (System.Boolean publicOnly, System.Boolean skipCheckThis, System.Boolean fillCache, System.Threading.StackCrawlMark& stackMark) [0x00027] in <c79628fadf574d3a8feae0871fad28ef>:0
at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00020] in <c79628fadf574d3a8feae0871fad28ef>:0
at System.Activator.CreateInstance (System.Type type) [0x00000] in <c79628fadf574d3a8feae0871fad28ef>:0
at WanzyeeStudio.Json.DictionaryConverter.ReadJson (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue, Newtonsoft.Json.JsonSerializer serializer) [0x00016] in C:\Users\Flekoun\Desktop\WOWSimulator\Assets\Plugins\WanzyeeStudio\Scripts\Runtime\Concrete\Json\DictionaryConverter.cs:56
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable (Newtonsoft.Json.JsonConverter converter, Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Object existingValue) [0x0004a] in /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:2175
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue (Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.JsonConverter propertyConverter, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty, Newtonsoft.Json.JsonReader reader, System.Object target) [0x00048] in /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:1035
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject (System.Object newObject, Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, System.String id) [0x00280] in /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:2415
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x00161] in /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:493
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerMember, System.Object existingValue) [0x0006d] in /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:300
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x000db] in /_/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs:202
at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00046] in /_/Src/Newtonsoft.Json/JsonSerializer.cs:907
at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in /_/Src/Newtonsoft.Json/JsonSerializer.cs:886
at Newtonsoft.Json.JsonConvert.DeserializeObject (System.String value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x0002d] in /_/Src/Newtonsoft.Json/JsonConvert.cs:837
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in /_/Src/Newtonsoft.Json/JsonConvert.cs:792
at Newtonsoft.Json.JsonConvert.DeserializeObject[T] (System.String value) [0x00000] in /_/Src/Newtonsoft.Json/JsonConvert.cs:720
at Microsoft.Playfab.Gaming.GSDK.CSharp.InternalSdk.GetConfiguration () [0x00033] in <8b4bd490621a44989b0153eb68604853>:0
Rethrow as GSDKInitializationException: Cannot read configuration file C:\PlayFabVmAgent\Output\PlayFabVmAgentOutput\2019-12-14T19-53-09\Config\SH0\gsdkConfig.json
at Microsoft.Playfab.Gaming.GSDK.CSharp.InternalSdk.GetConfiguration () [0x0004d] in <8b4bd490621a44989b0153eb68604853>:0
at Microsoft.Playfab.Gaming.GSDK.CSharp.InternalSdk.Start (System.Boolean debugLogs) [0x0001f] in <8b4bd490621a44989b0153eb68604853>:0
at Microsoft.Playfab.Gaming.GSDK.CSharp.GameserverSDK.LogMessage (System.String message) [0x00000] in <8b4bd490621a44989b0153eb68604853>:0
at PlayfabMultiplayer.Start () [0x00021] in C:\Simulator\Assets\Script\PlayfabMultiplayer.cs:37

Any idea what is going in here I am a little bit suspicious it has something to do with a problem you are describing here

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brandon@uprootstudios.com avatar image brandon@uprootstudios.com commented ·

@Garry Clark I can't reply above so I'm gonna reply here

@Jan Halamicek

We fixed the issue in two ways:

1. The issue only happened when building with IL2CPP backend, switching to Mono fixed it for us

2. Switching to the Unity-specific GSDK (see the "PlayFabMultiplayerSDK.unitypackage" file) both fixed all of these issues for us, and allowed us to build with IL2CPP if needed

Let me know if that works for you!

0 Likes 0 ·
Garry Clark avatar image
Garry Clark answered

Yeah I am using PlayFabSDK v. 2.79.191218 and GameserverSDK v. 1.64.191218

and I am still getting the error below when this line runs. config = GameserverSDK.getConfigSettings();

JsonSerializationException: Required property 'heartbeatEndpoint' not found in JSON. Path '', line 74, position 1.

Any ideas as this used to work and now blows up. Tried everything I know to try.

4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brandon@uprootstudios.com avatar image brandon@uprootstudios.com commented ·

@Garry Clark See my comment above. Switching from IL2CPP to Mono fixed it using the C# GSDK.

Otherwise you should try the Unity-specific GSDK instead of the C# one.

0 Likes 0 ·
Garry Clark avatar image Garry Clark brandon@uprootstudios.com commented ·

Brandon, Thank you for the suggestion and I should have stated that the backend is configured for Mono not IL2CPP. This has been working and all of a sudden stopped. I want to use the GameserverSDK as I am using the new thunderhead multiplayer stuff. I will try and switch to IL2CPP and back to Mono to see if maybe that does anything.

0 Likes 0 ·
Garry Clark avatar image Garry Clark Garry Clark commented ·

Also just to test I downloaded the github sample WindowsRunnerCSharp.exe and it is blowing up as well. Something doesn't seem to be working with the SDK at the moment.

'WindowsRunnerCSharp.exe' (CLR v4.0.30319: WindowsRunnerCSharp.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Exception thrown: 'Microsoft.Playfab.Gaming.GSDK.CSharp.GSDKInitializationException' in Microsoft.Playfab.Gaming.GSDK.CSharp.dll
The program '[11776] WindowsRunnerCSharp.exe' has exited with code 0 (0x0).

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.