You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Difficulties faced in using Message pack in xamarin forms #977
I'm trying to use Message Pack in Xamarin forms used the AOT tool too. But still, the Operation not supported in platform exception is thrown in Xamarin.Forms (iOS).
Steps followed:
Installed mpc tool.
Used don't mpc -i "{FormsProject.csproj path}" -o "{FormsProject directory path}"
Added the created message pack generated class to the forms project.
Used the following code in App.xaml.cs Initialize method
Also using System.Drawing.Drawing2D.Matrix throws the following error
[MonoDroid] at MessagePa07-10 18:06:01.269 I/MonoDroid(13495): MessagePack.MessagePackSerializationException: Failed to deserialize Project.Core.Models.SomeData Class value. ---> System.TypeInitializationException: The type initializer for 'FormatterCache`1' threw an exception. ---> MessagePack.Internal.MessagePackDynamicObjectResolverException: can't find public constructor. type:System.Drawing.Drawing2D.Matrix
[MonoDroid] at MessagePack.Internal.ObjectSerializationInfo.CreateOrNull (System.Type type, System.Boolean forceStringKey, System.Boolean contractless, System.Boolean allowPrivate) [0x009a0] in <23c4c9b023514c20801c8f07fd69206c>:0
[MonoDroid] at MessagePack.Internal.DynamicObjectTypeBuilder.BuildType (MessagePack.Internal.DynamicAssembly assembly, System.Type type, System.Boolean forceStringKey, System.Boolean contractless) [0x00015] in <23c4c9b023514c20801c8f07fd69206c>:0
Created a SO query for the same. Any help could be great.
The following line produces operation not supported on the platform exception in iOS.
var option = MessagePackSerializerOptions.Standard.WithResolver(StaticCompositeResolver.Instance);
I'm using
Xamarin.Forms version- 4.5.0.495
MessagePack version - 2.1.152
System.TypeInitializationException: The type initializer for 'MessagePackSerializerOptionsDefaultSettingsLazyInitializationHelper' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Resolvers.StandardResolver' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Internal.StandardResolverHelper' threw an exception. ---> System.TypeInitializationException: The type initializer for 'MessagePack.Resolvers.DynamicEnumResolver' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.pns.cs:129
at MessagePack.Internal.DynamicAssembly..ctor (System.String moduleName) [0x0001a] in <f04e2061de5c414991b8e36a20354820>:0
at MessagePack.Resolvers.DynamicEnumResolver..cctor () [0x00010] in <f04e2061de5c414991b8e36a20354820>:0
I didn't try it. I just reopened the issue since you're still working through the issue. I hope @neuecc will continue to help since I haven't really focused on AOT platforms as @neuecc has.
@neuecc I also cannot make MessagePack work with Xamarin.Forms on iOS.
Is there any way i can help? Any suggestion about what to see or where to start?
It is not a desirable behavior for the DynamicAssembly code to always be executed at initialization time.
I've discussed this before with @AArnott ,it should be to lazy.
Anyway, I'll impl to lazy init code.
Other features(#if..., more target platform, etc) are after.
Sorry for the late reply, I am a bit confused from the comment.
Should I call the DefaultOption setting code in a lazy method? Or is it something to be taken care of on the Message Pack side.
As much as I interpret from the comment -> DynamicAssembly code is executed at initialization all the time by message pack. And you are changing it to lazy loaded in message pack. And I have to wait for these changes.
@Nikhileshwar96 I don't think @neuecc was asking you to do anything. He was stating the problem, which he fixes in #996. Do you want to try out the build from that PR and see if it fixes your issue?
Sorry for the late reply. Tried the nugget from the pipeline. This fixed the reported issue. 😃
The fix works super nice in a simple xamarin forms app in iOS. (Both serialization and deserialization happening in the app itself)
While in my real project app, serialization occurs in the ASP .net project and I try to deserialize here. It throws the following exception.
Tested by serializing and deserializing the object in the app itself, it works.
Any suggestions to overcome this?
Thanks in advance.
MessagePack.MessagePackSerializationException: Failed to deserialize MyProject.Core.Models.RenderImageDetails value. ---> System.TypeInitializationException: The type initializer for 'FormatterCache`1' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Reflection.Emit.AssemblyBuilder.DefineDynamicAssembly (System.Reflection.AssemblyName name, System.Reflection.Emit.AssemblyBuilderAccess access) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.pns.cs:129
at MessagePack.Internal.DynamicAssembly..ctor (System.String moduleName) [0x0001a] in <06919c9ec1724eec910157da33d9547f>:0
at MessagePack.Resolvers.DynamicObjectResolver+<>c.<.cctor>b__4_0 () [0x00000] in <06919c9ec1724eec910157da33d9547f>:0
at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x00043] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:333
at System.Lazy`1[T].ExecutionAndPublication (System.LazyHelper executionAndPublication, System.Boolean useDefaultConstructor) [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:351
at System.Lazy`1[T].CreateValue () [0x00074] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:431
at System.Lazy`1[T].get_Value () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:509
at MessagePack.Resolvers.DynamicObjectResolver+FormatterCache`1[T]..cctor () [0x000a1] in <06919c9ec1724eec910157da33d9547f>:0
Yes. it is included.
On further examining found the following.
The RenderImageDetails has the following property, which I didn't add for testing in simple xamarin app.
public System.Drawing.Drawing2D.Matrix TransformationMatrix { get; set; }
WIthout which the message pack is able to serialize and deserialize the class. But with the matrix property, the above exception is thrown at serialization itself. (Checked the Generated code, it has the property's formatter code).
The error is reproduced in a simple xamarin app too (iOS).
Hi @neuecc
I didn't try custom formatter. Since web API has to be changed too (serializatoin happens there). We are trying to eliminate the matrix property, if not required. If that doesn't solve the issue, I'll have to incorporate the custom formatter.
Activity
neuecc commentedon Jul 13, 2020
answered at SO.
maybe lacked this line.
Nikhileshwar96 commentedon Jul 14, 2020
@neuecc
The following line produces operation not supported on the platform exception in iOS.
I'm using
Xamarin.Forms version- 4.5.0.495
MessagePack version - 2.1.152
Nikhileshwar96 commentedon Jul 15, 2020
@AArnott Was this exception replicating in your side?
I couldn't make MessagePack work in xamarin.forms iOS
Or is there anything I missed?
AArnott commentedon Jul 16, 2020
I didn't try it. I just reopened the issue since you're still working through the issue. I hope @neuecc will continue to help since I haven't really focused on AOT platforms as @neuecc has.
Nikhileshwar96 commentedon Jul 24, 2020
@neuecc Is there any way I can overcome this?
Can you suggest any steps to proceed further?
Jose7777 commentedon Jul 25, 2020
@neuecc I also cannot make MessagePack work with Xamarin.Forms on iOS.
Is there any way i can help? Any suggestion about what to see or where to start?
Thank you in advance!
neuecc commentedon Aug 5, 2020
It is not a desirable behavior for the DynamicAssembly code to always be executed at initialization time.
I've discussed this before with @AArnott ,it should be to lazy.
Anyway, I'll impl to lazy init code.
Other features(#if..., more target platform, etc) are after.
Nikhileshwar96 commentedon Aug 7, 2020
Hi @neuecc / @AArnott ,
Sorry for the late reply, I am a bit confused from the comment.
Should I call the DefaultOption setting code in a lazy method? Or is it something to be taken care of on the Message Pack side.
As much as I interpret from the comment -> DynamicAssembly code is executed at initialization all the time by message pack. And you are changing it to lazy loaded in message pack. And I have to wait for these changes.
Am I right?
AArnott commentedon Aug 7, 2020
@Nikhileshwar96 I don't think @neuecc was asking you to do anything. He was stating the problem, which he fixes in #996. Do you want to try out the build from that PR and see if it fixes your issue?
Nikhileshwar96 commentedon Aug 7, 2020
Sure @AArnott
How do I do that?
AArnott commentedon Aug 10, 2020
The Azure Pipelines CI pushed a package you can try installing to see.
https://dev.azure.com/ils0086/MessagePack-CSharp/_packaging?_a=package&feed=MessagePack-CI%40Local&package=MessagePack&protocolType=NuGet&version=2.1.165&view=overview
That page includes a "Connect to feed" button with instructions on how to consume the package from the CI feed.
Nikhileshwar96 commentedon Aug 14, 2020
Hi @AArnott / @neuecc
Sorry for the late reply. Tried the nugget from the pipeline. This fixed the reported issue. 😃
The fix works super nice in a simple xamarin forms app in iOS. (Both serialization and deserialization happening in the app itself)
While in my real project app, serialization occurs in the ASP .net project and I try to deserialize here. It throws the following exception.
Tested by serializing and deserializing the object in the app itself, it works.
Any suggestions to overcome this?
Thanks in advance.
AArnott commentedon Aug 14, 2020
Is the formatter for
MyProject.Core.Models.RenderImageDetailsincluded in the mpc generated code?Nikhileshwar96 commentedon Aug 14, 2020
Yes. it is included.
On further examining found the following.
The
RenderImageDetailshas the following property, which I didn't add for testing in simple xamarin app.WIthout which the message pack is able to serialize and deserialize the class. But with the matrix property, the above exception is thrown at serialization itself. (Checked the Generated code, it has the property's formatter code).
The error is reproduced in a simple xamarin app too (iOS).
AArnott commentedon Aug 15, 2020
I'm going to bow out of this one and invite @neuecc to step in since he's more familiar with mpc and how it interacts with the dynamic resolvers.
neuecc commentedon Aug 16, 2020
How about generating a custom
System.Drawing.Drawing2D.Matrixformatter first?Nikhileshwar96 commentedon Aug 19, 2020
Hi @neuecc
I didn't try custom formatter. Since web API has to be changed too (serializatoin happens there). We are trying to eliminate the matrix property, if not required. If that doesn't solve the issue, I'll have to incorporate the custom formatter.
Nikhileshwar96 commentedon Aug 30, 2020
We excluded the Transform matrix property and used the latest Message Pack version > 2.1.165. Works super fine.
👍 Thanks for supporting in making this work.
Closing this issue.