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 Deserialize #233

Closed muthukrish1985 closed 3 years ago

muthukrish1985 commented 3 years ago

We are getting this exception on deserialization. We are using NetJSON 1.3.3 version. We are having hard time on reproducing this issue again. please let us know if it is a known issue or there is a bug.

var deserializedInstance = NetJSON.NetJSON.Deserialize(json);

System.InvalidProgramException: Common Language Runtime detected an invalid program. at ExtractInt32(Char , Int32& , NetJSONSettings ) at SetResponse(Char , Int32& , Response , String , NetJSONSettings ) at CreateClassOrDictResponse(Char* , Int32& , NetJSONSettings ) at ReadResponse(String , NetJSONSettings ) at CacheManager.Serialization.Serializers.JsonCacheSerializer.Deserialize[T](String value)

rpgmaker commented 3 years ago

I don't remember such an error occurring in any version. The error message is a generic message for invalid IL code. What version of .net are you using?

Thanks,

muthukrish1985 commented 3 years ago

We are using NETJSON library in our library project which is targeted to netstandard2.0 and our library is consumed in .Netcore 3.1 hosting project.

muthukrish1985 commented 3 years ago

we are using serverless architecture and using .NETCore 3.0 ReadyToRun feature which will pre-compile the code and hosted in AWS lambda.

rpgmaker commented 3 years ago

Good to know. I will try to test using. NetCore 3.0.

muthukrish1985 commented 3 years ago

Thanks. Actually we are using .Netcore 3.1 for our hosting application (web api). ReadyToRun feature was introduced as part of .NETCore 3.0 and it is available part of 3.1 as well.

rpgmaker commented 3 years ago

Ok, thanks for the update.

muthukrish1985 commented 3 years ago

@rpgmaker - Can you please share an update if you get a chance to look into this issue?

rpgmaker commented 3 years ago

I did look into the extract method (GenerateExtractValueFor) and nothing has jump out to me as been able to generate invalid IL while using integer (Int32) values. None of the unit test regarding loading integer fails nor test with class that has integer.

Since you can't reproduce it either. If you can provide me with your class and sample payload that failed then it might help a little too.

Thanks,

muthukrish1985 commented 3 years ago

Thanks for the update. Even we tried to do the unit test for NETJSON deserialization method. We did not face this issue. Unfortunately we are not sure about the payload which caused this issue.

We were trying with the sample payload with int32 type. We did not see any issue. We faced this issue once in production afterwards we were not able to see this issue.

We will keep an eye on this issue and see if it pops again in future.

rpgmaker commented 3 years ago

I was thinking maybe this could be possible if we use a long/double/decimal in a json payload and try to use int to deserialize it. Just a guess since it will use ldc.i4 and box int32 instead of int64 and might cause failure since the emitted IL might not be correct assuming it does not automatically does a arithmetic overflow.

Most likely a decimal/double since long will/should result in arithmetic overflow.

If i find anything once i test the ideas above i will let you know.

muthukrish1985 commented 3 years ago

Sure. Make sense. please keep me posted on the outcome.

rpgmaker commented 3 years ago

Sorry I have not updated this in a while. Still have not been able to determine root cause that would throw the specific type of exception. Any idea @wmjordan ?

wmjordan commented 3 years ago

Is there any sample code available to reproduce the problem? It is hard to figure out what have been generated to the dynamic assembly with the stack trace only.

rpgmaker commented 3 years ago

So, I have not received any sample code that produce this issue. All that is mention is that it happened when using netcore 3.1.

wmjordan commented 3 years ago

Yep. Just let it be, if no more info is provide :)

rpgmaker commented 3 years ago

I guess that makes sense. @muthukrish1985 , please reopen if you have more details.