-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
WarningException on System.DateTime when using .NET Native Compilation #72
Comments
I was able to work around this issue by marking the DateTime-properies with Exclude, and adding a string-property that wraps the original DateTime prop. Something like:
|
We could bypass the problem by creating a custom formatter for this type, but the same issue will likely pop up with other types. For now, you can try just including the two relevant props:
Like this: config.ConfigType<DateTime>()
.ConfigMember(p => p.Kind).Include()
.ConfigMember(p => p.Ticks).Include(); Definitely let me know if that helps, and if you get a similar problem with other types. |
I can confirm this works when marking the Kind & Ticks properties with Include as you've suggested. For now, this has been the only type I've seen this error on. (We were using JSON (and XML) serialization before Ceras, never had any issues with DateTimes.) This issue isn't a priority for us anymore, as I'm using the "AsString" variant I described above. This allows me to solve another issue regarding differences in timezones when passing dates between my server and client. |
Thanks for testing that! 😄 ❤️ config.ConfigType<DateTime>()
.CustomResolver = (c, t) => c.Advanced
.GetFormatterResolver<DynamicObjectFormatterResolver>()
.GetFormatter(t); Does Ceras still round-trip a
So I've looked into all of this some more... Since the definition for But it seems the UWP libraries are written in a slightly different syntax, so that there's no explicit/manual field definition! So when Ceras "discoveres" the type and creates the Like other serializers, Ceras also uses a Formatter made specifically for Ceras/src/Ceras/Resolvers/StandardFormatterResolver.cs Lines 199 to 212 in cc24d60
I'm hesitant about going with the straight-forward approach (just disabling the check for types that Ceras can handle with a built-in formatter), because the user can always override the formatter. But then again maybe that's a rare / advanced scenario and someone who changes the formatter for a built-in type is probably aware of the potential issues. Maybe the easiest solution would be to just make an exception for |
Hmm, To test it this time, I've written a small program. But now the previous workaround (where you mark the Kind and Ticks properties to be included) no longer works!
It is referring to the property "Kind" here. But I suspect it will also throw this error on the property Ticks. I saw in the DateTime class that both only have a getter, and no setter. If I try your new config, it throws the original WarningException: Trying a config that tries to include the field I've published my sample app here: https://github.com/RCTycooner/CerasTryouts Let me know if I can help with anything regarding this. As stated before, our production code will be using the wrapped "AsString" property. |
The resolver part was missing from there. When you set those two fields to be included that only changed the TypeConfig. That means it was still using the built-in Most settings in TypeConfig are only relevant to
I see, seems like those two members really are "getter-only properties".
In that case a field with that name doesn't exist.
In any case, the built-in formatter that is used by default should work perfectly on any platform.
The only thing left to do is deciding on how to handle this in the future. |
The ideal situation is ofcourse that basic types such as a DateTime work out of the box. So I would add a special condition for DateTimes. |
Working with Ceras 4.1.7 in an UWP project (targetting build 16299 of Win10).
With .NET Native tool chain compilation disabled, everything works fine.
However, with that option enabled (and I need it for release builds), I'm getting the following WarningException from Ceras:
Ceras.Exceptions.WarningException: Warning: The type 'System.DateTime' is a struct and by default Ceras serializes structs only through their fields. This struct has only auto-properties, for which the compiler generates hidden 'backing-fields' that are all marked as 'CompilerGenerated'.
You can do multiple things to fix this:
(1) Change all properties to fields.
(2) Explicitly include the properties either with the [Include] attribute, or [MemberConfig].
(3) Disable this warning-exception in 'config.Warnings'.
at Ceras.TypeConfig.Seal() + 0x2b8
at Ceras.CerasSerializer.CreatePrimarySchema(Type, Boolean) + 0x90
at Ceras.CerasSerializer.CreateMetaData(Type, Boolean) + 0x184
at Ceras.CerasSerializer.GetReferenceFormatter(Type) + 0x27
at Ceras.Formatters.DynamicFormatter
1.GenerateSerializer(CerasSerializer, Schema, Boolean, Boolean) + 0x491 at Ceras.Formatters.DynamicFormatter
1.Initialize() + 0x4eat Ceras.CerasSerializer.PrepareFormatter(IFormatter) + 0x28
at Ceras.CerasSerializer.GetSpecificFormatter(Type, TypeMetaData) + 0x15a
at Ceras.CerasSerializer.GetSpecificFormatter(Type) + 0x2d
at Ceras.Formatters.ReferenceFormatter
1.GetOrCreateEntry(Type) + 0xc7 at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x2b7at Ceras.Formatters.CollectionFormatter
2.Deserialize(Byte[], Int32&, TCollection&) + 0x24a at System.Action
3.Invoke(T1, T2, T3) + 0x24at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x372 at _$ILCT$.$ILT$ReflectionDynamicInvoke$.InvokeRetVIRR[T0, T1, T2](Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x74 at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2f at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x10c --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x14 at System.Linq.Expressions.Interpreter.ByRefMethodInfoCallInstruction.Run(InterpretedFrame) + 0x203 at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x25 at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[]) + 0x96 at Ceras.Formatters.DeserializeDelegate
1.InvokeObjectArrayThunk(Byte[], Int32&, T&) + 0x86at Ceras.Formatters.DynamicFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x24 at System.Action
3.Invoke(T1, T2, T3) + 0x24at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x372 at _$ILCT$.$ILT$ReflectionDynamicInvoke$.InvokeRetVIRR[T0, T1, T2](Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x74 at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2f at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x10c --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x14 at System.Linq.Expressions.Interpreter.ByRefMethodInfoCallInstruction.Run(InterpretedFrame) + 0x203 at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x25 at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[]) + 0x96 at Ceras.Formatters.DeserializeDelegate
1.InvokeObjectArrayThunk(Byte[], Int32&, T&) + 0x86at Ceras.Formatters.DynamicFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x24 at System.Action
3.Invoke(T1, T2, T3) + 0x24at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x372 at Ceras.Formatters.CollectionFormatter
2.Deserialize(Byte[], Int32&, TCollection&) + 0x24aat System.Action
3.Invoke(T1, T2, T3) + 0x24 at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x372at _$ILCT$.$ILT$ReflectionDynamicInvoke$.InvokeRetVIRR[T0, T1, T2](Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x74
at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2f
at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x10c
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x14
at System.Linq.Expressions.Interpreter.ByRefMethodInfoCallInstruction.Run(InterpretedFrame) + 0x203
at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x25
at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[]) + 0x96
at Ceras.Formatters.DeserializeDelegate
1.InvokeObjectArrayThunk(Byte[], Int32&, T&) + 0x86 at Ceras.Formatters.DynamicFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x24at System.Action
3.Invoke(T1, T2, T3) + 0x24 at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x372at _$ILCT$.$ILT$ReflectionDynamicInvoke$.InvokeRetVIRR[T0, T1, T2](Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x74
at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2f
at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x10c
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x14
at System.Linq.Expressions.Interpreter.ByRefMethodInfoCallInstruction.Run(InterpretedFrame) + 0x203
at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x25
at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[]) + 0x96
at Ceras.Formatters.DeserializeDelegate
1.InvokeObjectArrayThunk(Byte[], Int32&, T&) + 0x86 at Ceras.Formatters.DynamicFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x24at System.Action
3.Invoke(T1, T2, T3) + 0x24 at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x372at _$ILCT$.$ILT$ReflectionDynamicInvoke$.InvokeRetVIRR[T0, T1, T2](Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x74
at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2f
at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x10c
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x14
at System.Linq.Expressions.Interpreter.ByRefMethodInfoCallInstruction.Run(InterpretedFrame) + 0x203
at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x25
at System.Linq.Expressions.Interpreter.LightLambda.RunVoid(Object[]) + 0x96
at Ceras.Formatters.DeserializeDelegate
1.InvokeObjectArrayThunk(Byte[], Int32&, T&) + 0x86 at Ceras.Formatters.DynamicFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x24at System.Action
3.Invoke(T1, T2, T3) + 0x24 at Ceras.Formatters.ReferenceFormatter
1.Deserialize(Byte[], Int32&, T&) + 0x372at Ceras.CerasSerializer.Deserialize[T](T&, Byte[], Int32&, Int32) + 0x131
at Ceras.CerasSerializer.DeserializeT + 0x35
at Calidos.Maat.ClientData.ServiceClient.WebApiCerasBroker.DeSerializeT + 0x5d
All my classes are marked with
[MemberConfig(TargetMember.AllProperties)]
How can I resolve this?
Thx,
Tom
The text was updated successfully, but these errors were encountered: