AqlaSolutions / AqlaSerializer

Binary serializer with full .NET support!
http://www.aqla.net
Other
17 stars 3 forks source link

Reference tracking error message only for release build but not for debug build #58

Open inethui opened 9 months ago

inethui commented 9 months ago

We got the error "A reference-tracked object changed reference during deserialization" when running with Aqla release build, and the offending object type is a value type. It works fine with Aqla debug build.

Any idea why the release build and debug build behave so differently. How to troubleshoot this kind of problem as I can't replicate the issue in debugging mode?

The related code is in "NetObjectHelpers.ReadNetObject_End". The thing confuses me is that the variable "wasNull" should never be null if the parameter "type" is a value type, so the reference checking will never be conducted for value type of objects.

Further investigation discovered that with Aqla release build, if there is a field defined as "object" type and a struct value is assigned to it, then deserialization fails with the above error. Looking into Aqla's code, in method "CompilerContext.CastToObject", the value is re-boxed and thus a new reference is assign to the struct value.

Any suggestion on how to fix this?