Closed cubed-it closed 5 years ago
Thanks for the details. I can look into the code to see what causes it. Thanks
Could you give an example of what you are trying to do? I could not reproduce it. Is the issue trying to deserialize ulong value into an int?
When i tried type mismatch. I only got a stackoverflow exception instead of the access violation exception. So based on my test so far, an example to reproduce will be really useful. Thanks
My fault, I forgot to mention that it is a Flag-Enum. Sorry :(
[Flags]
public enum ULongEnum : ulong
{
ULongEnumValueA = 0x00400,
ULongEnumValueB = 0x400000000
}
public class ULongClass
{
public ULongEnum LongEnum { get; set; }
}
var obj = new ULongClass() {LongEnum = ULongEnum.ULongEnumValueA | ULongEnum.ULongEnumValueB};
var json = NetJSON.NetJSON.Serialize(obj);
var dto = NetJSON.NetJSON.Deserialize<ULongClass>(json);
So that will result in issue 1, but unfortunately not in mystic issue 2...
I see. Thanks for the details
Regarding my second problem, I was now able to reproduce the problem. It occurs when a long or ulong enum is used. However, exclusively out of a uwp project. Your example code within a UWP project then generates the following message. Unfortunately there is almost no further info. Looks like a bug in the platform. :(
The problem is in the flagenumToStr method that try to cast to int and check for zero as an optimization. If you remove that then it works fine. But I found a weird bug when in release mode that give junk data when a single value is used as the enum from the flag. Trying to figure out the cause of it.
One question not related to my problem: If I serialize an interface type, why are properties of the base interface ignored?
Can I see an example of what you are trying to do?
Thanks
Sure:
public class SimpleClass : ISimpleClass
{
public string SimpleClassProp { get; set; }
public string SimpleClassBaseProp { get; set; }
}
public interface ISimpleClass : ISimpleClassBase
{
string SimpleClassProp { get; set; }
}
public interface ISimpleClassBase
{
string SimpleClassBaseProp { get; set; }
}
var jsonSettingsB = new NetJSON.NetJSONSettings() { DateFormat = NetJSON.NetJSONDateFormat.ISO, SkipDefaultValue = false, UseEnumString = true, };
var sc = new SimpleClass();
var isc = (ISimpleClass) sc;
var scs = NetJSON.NetJSON.Serialize(typeof(SimpleClass), sc, jsonSettingsB);
var iscs = NetJSON.NetJSON.Serialize(typeof(ISimpleClass), isc, jsonSettingsB);
So the interface will not get the other properties since it does not exists. It only exists in the class itself. You need to enable NetJson.IncludeTypeInformation = true and try again
Please verify if the changes i did solves your problem by using the code from the branch. If so, i can create a nuget package for it. In regards to the enumeration ulong.
Please a separate ticket to discuss the serialization of Interface
Thanks,
The first problem FlagEnumToString is solved, thanks! :) However the serialization issue has only been noticed by coincidence. My main issue is still present, the deserialization of long enum in uwp as described here: https://github.com/rpgmaker/NetJSON/issues/219#issuecomment-495093598 (As I also said before, it looks like a platform error to me. it doesn't have a big priority for me either, since we can workaround without using a long enum for the time being. nevertheless, it remains an unintentional misbehaviour...)
Hey there,
I have found two issues:
It happens when CreateSerializer() is called on the last Emit call. (Maybe this is nocht the actual line, because it was a dotpeak decompiled assembly and this is sometime not exactly at the right line, could be one more maybe). However, there is not any more information I get or can provide. Maybe you have any idea or hint what could cause this or how to make a further diagnosis?
Thank!