rpgmaker / NetJSON

Faster than Any Binary? Benchmark: http://theburningmonk.com/2014/08/json-serializers-benchmarks-updated-2/
MIT License
225 stars 29 forks source link

Getting Exception when serializing a struct #220

Closed peter-ringba closed 4 years ago

peter-ringba commented 5 years ago
Unhandled Exception: System.TypeInitializationException: The type initializer for 'NetJSONCachedSerializer`1' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at NetJSON.NetJSON.GetMemberInfoValue(ILGenerator il, NetJSONMemberInfo parameter)
   at NetJSON.NetJSON.<>c__DisplayClass363_0.<GenerateGetClassOrDictFor>b__1(ILGenerator msil)
   at NetJSON.NetJSON.ILFixedWhile(ILGenerator il, Action`5 whileAction, Boolean needBreak, Action`1 returnAction, Action`2 beforeAction, Action`2 beginIndexIf, Action`2 endIndexIf)
   at NetJSON.NetJSON.GenerateGetClassOrDictFor(TypeBuilder typeBuilder, Type type)
   at NetJSON.NetJSON.WriteDeserializeMethodFor(TypeBuilder typeBuilder, Type type)
   at NetJSON.NetJSON.GenerateTypeBuilder(Type objType, ModuleBuilder module)
   at NetJSON.NetJSON.Generate(Type objType)
   at NetJSON.NetJSON.NetJSONCachedSerializer`1.GetSerializer()
   at NetJSON.NetJSON.NetJSONCachedSerializer`1..cctor()
public struct LogEntry
    {
        public string DateTimeString;
        public string ServerName;
        public long Epoch;
        public bool IsSuccess;
        public string LogId;
        public string RequestId;
        public string action;
        [NonSerialized]
        public long ticks;
        public double ms;
        public string failMessage;
        public SEVERITY severity;
        [NonSerialized]
        public string argsJson;

      //  public LogEntry() { }

        public LogEntry(string logId, string requestId, string action, long ticks, string failMessage, SEVERITY severity, string argsJson) : this()
        {
            LogId = logId;
            this.action = action;
            this.ticks = ticks;
            this.failMessage = failMessage;
            this.severity = severity;
            IsSuccess = false;
            RequestId = requestId;
            Epoch = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
            DateTimeString = DateTime.UtcNow.ToString("o");
            ServerName = Environment.MachineName;
            this.argsJson = argsJson;
        }

    }

    public enum SEVERITY
    {
        ERROR
    }
rpgmaker commented 5 years ago

Thanks for the find. Could you give an example payload for the failure? Thanks

rpgmaker commented 5 years ago

Here is an example similar to your that already exists in the test suite which uses a struct and does not fail. Note, that it does not have a default constructor either and the test pass.

Something similar to the test i have below will be appreciated. Thanks

image

image

rpgmaker commented 5 years ago

Any example would be nice. Thanks

rpgmaker commented 4 years ago

Please reopen this issue if you are able to reproduce the issue again. Thanks