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
How to create a blank MessagePackSerializerOptions instance without standard resolver? #701
I need to create a MessagePackSerializerOptions with GeneratedResolver. It seems that I can only create one by accessing the static Standard property which tries to initialize a standard resolver. But standard resolver contains dynamic resolvers which are not supported by Xamarin and System.PlatformNotSupportedException was thrown.
Interesting. So even the initialization of the static Standard instance throws an exception on these platforms? Can you share a callstack? That sounds like something we need to fix.
There's no such thing as MessagePackSerializerOptions without a resolver, but evidently we need to provide a way for you to get/create an instance that conforms to your platform.
Maybe we'll change Standard to not throw on these platforms. Or maybe we can add a static Create factory method on the type to allow you to specify the resolver.
This is a duplicate of #159 since both Xamarin.iOS and UWP when compiled with .NET Native do not support Ref.Emit, which is where the PlatformNotSupportedException is coming from.
The practice in this case is to use CompositeResolver.Create.
So when you compose with StandardResolver, the type that raises PlatformNotSupportedException has been handled by the previous GeneratedResolver.
If you are still unsatisfied, you can add the sub resolvers of StandardResolver with CompositeResolver.Create.
@neuecc The problem isn't creating the resolver. It's getting an instance of MessagePackSerializationOptions to set the resolver on. The only obvious one is MessagePackSerializationOptions.Standard, which throws on these platforms.
@kpto for now I suspect using PrimitiveObjectResolver.Options as your basis and changing out the resolver on it will work. But that doesn't seem discoverable IMO.
Thought that PlatformNotSupportedException will issued when touched StandardResolver.GetFormatter<T> that T is user define type.
But, ah, okay. StandardResolver.Resolvers uses DynamicObjectResolver.Instance
that create new DynamicAssembly and it uses AssemblyBuilder.DefineDynamicAssembly immediately.
Well, this is different from what I thought and it is not good behavior.
Just found that there are preprocessor directive trying to exclude dynamic resolvers from the StandardResolver, but the spelling of the .NetStandard symbol is wrong so they are not excluded. I have created pull request #705 to correct the spelling. I have deployed it to both simulator and real iPad and it works.
Okay, I think I did it wrong, correcting the spelling ruins the test because that the test running in .NetFramework use the library targeting .NetStandard, and all tests that test dynamic resolvers failed.
I don't understand why some code is excluded from .NetStandard2.0 when the library is targeting .NetStandard2.0.
If NET_STANDARD_2_0 is not a misspell but a custom symbol instead, I don't see there is any .csproj defining it as well when I try to grep all files that contains this string, except that it appears in ./src/MessagePack.UnityClient/code_generate.bat
I think this problem is beyond my knowledge, sorry about that, I am new in programming.
It's very odd, I agree. But NET_STANDARD_2_0 is set by Unity when in the unity build, which is not represented in any csproj file. The "misspelling" is useful though because it means we can detect when it's Unity's version of netstandard2.0 which is not quite the same thing as netstandard2.0 itself.
The proper fix to this may be #703. I'm awaiting @neuecc's review of that before finishing it.
Activity
AArnott commentedon Dec 4, 2019
Interesting. So even the initialization of the static
Standardinstance throws an exception on these platforms? Can you share a callstack? That sounds like something we need to fix.There's no such thing as
MessagePackSerializerOptionswithout a resolver, but evidently we need to provide a way for you to get/create an instance that conforms to your platform.Maybe we'll change
Standardto not throw on these platforms. Or maybe we can add a staticCreatefactory method on the type to allow you to specify the resolver.AArnott commentedon Dec 4, 2019
This is a duplicate of #159 since both Xamarin.iOS and UWP when compiled with .NET Native do not support Ref.Emit, which is where the
PlatformNotSupportedExceptionis coming from.neuecc commentedon Dec 5, 2019
The practice in this case is to use
CompositeResolver.Create.So when you compose with
StandardResolver, the type that raisesPlatformNotSupportedExceptionhas been handled by the previousGeneratedResolver.If you are still unsatisfied, you can add the sub resolvers of
StandardResolverwithCompositeResolver.Create.AArnott commentedon Dec 5, 2019
@neuecc The problem isn't creating the resolver. It's getting an instance of
MessagePackSerializationOptionsto set the resolver on. The only obvious one isMessagePackSerializationOptions.Standard, which throws on these platforms.@kpto for now I suspect using
PrimitiveObjectResolver.Optionsas your basis and changing out the resolver on it will work. But that doesn't seem discoverable IMO.neuecc commentedon Dec 6, 2019
Thought that
PlatformNotSupportedExceptionwill issued when touchedStandardResolver.GetFormatter<T>that T is user define type.But, ah, okay.
StandardResolver.ResolversusesDynamicObjectResolver.Instancethat create
new DynamicAssemblyand it usesAssemblyBuilder.DefineDynamicAssemblyimmediately.Well, this is different from what I thought and it is not good behavior.
kpto commentedon Dec 6, 2019
Just found that there are preprocessor directive trying to exclude dynamic resolvers from the StandardResolver, but the spelling of the .NetStandard symbol is wrong so they are not excluded. I have created pull request #705 to correct the spelling. I have deployed it to both simulator and real iPad and it works.
Should be
NETSTANDARD2_0instead ofNET_STANDARD_2_0according to Microsoft doc:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if
This is the first time I contribute open source project, I hope I have done it correctly and politely.
kpto commentedon Dec 6, 2019
Okay, I think I did it wrong, correcting the spelling ruins the test because that the test running in .NetFramework use the library targeting .NetStandard, and all tests that test dynamic resolvers failed.
I don't understand why some code is excluded from .NetStandard2.0 when the library is targeting .NetStandard2.0.
If
NET_STANDARD_2_0is not a misspell but a custom symbol instead, I don't see there is any .csproj defining it as well when I try to grep all files that contains this string, except that it appears in./src/MessagePack.UnityClient/code_generate.batI think this problem is beyond my knowledge, sorry about that, I am new in programming.
AArnott commentedon Dec 6, 2019
It's very odd, I agree. But
NET_STANDARD_2_0is set by Unity when in the unity build, which is not represented in any csproj file. The "misspelling" is useful though because it means we can detect when it's Unity's version of netstandard2.0 which is not quite the same thing as netstandard2.0 itself.The proper fix to this may be #703. I'm awaiting @neuecc's review of that before finishing it.