rpgmaker / NetJSON

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

Deserialization into simple char causes System.IndexOutOfRangeException #227

Closed Micke90s closed 4 years ago

Micke90s commented 4 years ago

Hallo,

could you please check the following behavior?

I tried to update NetJSON from 1.2.1.8 (I am not absolute sure about the version. It also could be older) to the current version. Unfortunately I got the problem that the existing classes causing the exception “System.IndexOutOfRangeException” when char is used as attribute.

  public class CNTL_SIMPLE_EVENT {
    public int EVENTID;
    //public String APPL_EVENT; //Works perfect
    public char APPL_EVENT; //Causes Exception
  }
  class Program  {
    static void Main(string[] args)    {
      var json = "{\"EVENTID\":19 ,\"APPL_EVENT\":\"\"}";
      var simple = NetJSON.NetJSON.Deserialize<CNTL_SIMPLE_EVENT>(json);
    }
  }
rpgmaker commented 4 years ago

Sure, will take a look at it.

Thanks,

rpgmaker commented 4 years ago

Please test again. I have fixed and published it to nuget as 1.3.3 which should be available soon.

Thanks again for the finding.

Micke90s commented 4 years ago

Thank you very much. Now it works perfect.


At the moment I have a second problem with the update from 1.2.1.8 to 1.3.2/1.3.3. I think that the problem is caused by my project configuration. Unfortunately, I haven't been able to find the problem yet. If you would have any tip for me it would be great.

After the update the following exception is thrown:

System.TypeInitializationException: "The type initializer for "NetJSONCachedSerializer`1" threw an exception."
Inner Exception
System.TypeLoadException: Access is denied: "NetJSON.NetJSONSerializer`1[System.Collections.Generic.List`1[bit.CNTL_SIMPLE_EVENT]]".

Exception

The direct access works fine:

        //NetJson.cs
        internal static NetJSONSerializer<T> GetSerializer<T>() {
            //Works fine
            List<bit.CNTL_SIMPLE_EVENT> list = new List<bit.CNTL_SIMPLE_EVENT>();
            //Thorws exception
            return NetJSONCachedSerializer<T>.Serializer;
        }

The used class is defined as public public class CNTL_SIMPLE_EVENT and part of the same project as the NetJSON cs-file

Before update: CurrentVersion

After update: NewVersion

It would be great if you could give me a tip to solve this.

Thank you