-
Notifications
You must be signed in to change notification settings - Fork 29
Closed
Description
I'm testing NetJSON in Unity with this simple code:
struct SimpleObjectStruct
{
public int ID;
public string Name;
public string Value;
}
public void TestSimpleStruct()
{
var settings = new NetJSON.NetJSONSettings();
var data = new SimpleObjectStruct() { ID = 10, Name = "Test", Value = "Tester" };
var json = NetJSON.NetJSON.Serialize(data, settings);
UnityEngine.Debug.Log(json);
var data2 = NetJSON.NetJSON.Deserialize<SimpleObjectStruct>(json, settings);
UnityEngine.Debug.Log(data2);
}
It throws error on var json = NetJSON.NetJSON.Serialize(data, settings);
InvalidProgramException: Invalid IL code in (wrapper dynamic-method) object:DeserializeValueTextReaderSettings (System.IO.TextReader,NetJSON.NetJSONSettings): IL_0006: ldarg.2
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, System.Boolean throwOnBindFailure, System.Boolean allowClosed) (at <801a4b5b9f964ad7bbc7574456774626>:0)
System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method) (at <801a4b5b9f964ad7bbc7574456774626>:0)
System.Reflection.Emit.DynamicMethod.CreateDelegate (System.Type delegateType) (at <801a4b5b9f964ad7bbc7574456774626>:0)
NetJSON.NetJSON+DynamicNetJSONSerializer`1[T].CreateDeserializerWithTextReaderSettings () (at <b1d0275b3ef44169a919f0dca690658f>:0)
NetJSON.NetJSON+DynamicNetJSONSerializer`1[T]..ctor () (at <b1d0275b3ef44169a919f0dca690658f>:0)
NetJSON.NetJSON+NetJSONCachedSerializer`1[T].GetSerializer () (at <b1d0275b3ef44169a919f0dca690658f>:0)
NetJSON.NetJSON+NetJSONCachedSerializer`1[T]..cctor () (at <b1d0275b3ef44169a919f0dca690658f>:0)
Rethrow as TypeInitializationException: The type initializer for 'NetJSONCachedSerializer`1' threw an exception.
NetJSON.NetJSON.Serialize[T] (T value) (at <b1d0275b3ef44169a919f0dca690658f>:0)
moveDetection.TestSimpleStruct () (at Assets/moveDetection.cs:97)
moveDetection.Start () (at Assets/moveDetection.cs:18)
I've also written a class for testing, same error on Serialize
function.
public class SimpleObject
{
public int ID { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
// NetJSON
void TestNetJSON()
{
var o = new SimpleObject() { ID = 100, Name = "Test", Value = "Value" };
var output = NetJSON.NetJSON.Serialize(o);
UnityEngine.Debug.Log(output);
var newObject = NetJSON.NetJSON.Deserialize<SimpleObject>(output);
UnityEngine.Debug.Log(newObject);
}
I'm using Unity2021.3.18f1 with .NET Standard 2.1
Metadata
Metadata
Assignees
Labels
No labels