Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ulong enum #219

Closed
cubed-it opened this issue May 20, 2019 · 13 comments
Closed

ulong enum #219

cubed-it opened this issue May 20, 2019 · 13 comments

Comments

@cubed-it
Copy link

cubed-it commented May 20, 2019

Hey there,

I have found two issues:

  1. FlagEnumToString is throwing an InvalidCastException if you have a enum value that is larger than an int32.
  2. This one is tricky and I unfortunatelly cannot reproduce it. We have changed a enum from uint to ulong and when deserializing we get the following exception:
Ein Ausnahmefehler des Typs "System.AccessViolationException" ist in NetJSON.dll aufgetreten.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

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!

@rpgmaker
Copy link
Owner

Thanks for the details. I can look into the code to see what causes it. Thanks

@rpgmaker
Copy link
Owner

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?

image

@rpgmaker
Copy link
Owner

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

image

@cubed-it
Copy link
Author

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...

@rpgmaker
Copy link
Owner

I see. Thanks for the details

@cubed-it
Copy link
Author

cubed-it commented May 23, 2019

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. :(

longex

@rpgmaker
Copy link
Owner

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.

@cubed-it
Copy link
Author

One question not related to my problem: If I serialize an interface type, why are properties of the base interface ignored?

@rpgmaker
Copy link
Owner

Can I see an example of what you are trying to do?

Thanks

@cubed-it
Copy link
Author

Sure:
image


   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);

@rpgmaker
Copy link
Owner

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

@rpgmaker
Copy link
Owner

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,

@cubed-it
Copy link
Author

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: #219 (comment)
(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...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants