home: System.PlatformNotSupportedException with UWP and .Net Native
Hello, I would like to use the serializer in a UWP application but when I compile with .Net Native turned on I get “System.PlatformNotSupportedException: ‘Dynamic code generation is not supported on this platform.’”. Do you think it could be fixed or it means major changes in the serializer. I also attached a sample project. Just hit the ‘Test’ button. TestSerializer.zip
This is the callstack that I am getting:
at System.Reflection.Emit.ReflectionEmitThrower.ThrowPlatformNotSupportedException() in f:\dd\ndp\fxcore\CoreRT\src\System.Private.CoreLib\src\System\Reflection\Emit\ReflectionEmitThrower.cs:line 11
at System.Reflection.Emit.DynamicMethod…ctor(String name, Type returnType, Type[] parameterTypes, Module m, Boolean skipVisibility) in f:\dd\ndp\fxcore\CoreRT\src\System.Private.CoreLib\src\System\Reflection\Emit\DynamicMethod.cs:line 38
at ExtendedXmlSerializer.Core.LightInject.ServiceContainer.DynamicMethodSkeleton.CreateDynamicMethod(Type returnType, Type[] parameterTypes) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\LightInject\LightInject.cs:line 4031
at ExtendedXmlSerializer.Core.LightInject.ServiceContainer.DynamicMethodSkeleton…ctor(Type returnType, Type[] parameterTypes) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\LightInject\LightInject.cs:line 4007
at ExtendedXmlSerializer.Core.LightInject.ServiceContainer.<>c.<.ctor>b__22_1(Type returnType, Type[] parameterTypes) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\LightInject\LightInject.cs:line 1903
at System.Func3.Invoke(T1 arg1, T2 arg2) at ExtendedXmlSerializer.Core.LightInject.ServiceContainer.CreateDynamicMethodDelegate(Action
1 serviceEmitter) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\LightInject\LightInject.cs:line 3017
at ExtendedXmlSerializer.Core.LightInject.ServiceContainer.CreateDelegate(Type serviceType, String serviceName, Boolean throwError) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\LightInject\LightInject.cs:line 3905
at ExtendedXmlSerializer.Core.LightInject.ServiceContainer.CreateDefaultDelegate(Type serviceType, Boolean throwError) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\LightInject\LightInject.cs:line 3868
at ExtendedXmlSerializer.Core.LightInject.ServiceContainer.GetInstance(Type serviceType) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\LightInject\LightInject.cs:line 2732
at ExtendedXmlSerializer.ExtensionModel.Services.GetService(Type serviceType) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\ExtensionModel\Services.cs:line 184
at ExtendedXmlSerializer.Core.Extensions.Get[T](IServiceProvider this) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Core\Extensions.cs:line 217
at ExtendedXmlSerializer.Configuration.RootContext.Create() in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Configuration\RootContext.cs:line 60
at ExtendedXmlSerializer.Configuration.Extensions.Create(IContext this) in C:\projects\extendedxmlserializer\src\ExtendedXmlSerializer\Configuration\Extensions.cs:line 41
at TestSerializer.MainPage.Button_Click(Object sender, RoutedEventArgs e) in C:\Projects\tests\TestSerializer\TestSerializer\MainPage.xaml.cs:line 36
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 29 (15 by maintainers)
Commits related to this issue
- Updating LightInject to dependency, removing LightInject.Source. #269 — committed to ExtendedXmlSerializer/home by Mike-E-angelo 5 years ago
@MagicAndre1981 Actually had to go digging for the answer to this one. I’m glad I did because the checks were originally introduced in 2011 during the development work for what would become .NET Framework 4.5 for Windows 8 (.NET Core shares a lot with this codebase). The goal was to help better support Windows Store apps (nee Metro at the time) and in particular, deliver on various guarantees around security (you may recall Windows AppContainer being a new hotness feature back then).
The CoreCLR we ship for UWP Debug has this check to this day. Here’s the branch we ship it out of if you want to take a look.
My guess is that this was added due to an overabundance of caution but without more analysis it would be hard to tell. In fact, the latest sources for CoreCLR no longer contain any of these checks. I would guess that whatever solution we provide for .NET Core 5 shipping into the Microsoft Store will ship from these more modern sources and not have the check.
Hope that helps.
My pleasure. Always fun to go crawling through older repositories. Certainly let me know if there’s other UWP oddities. I don’t always have time to dig in but I often cannot help myself.
I’m a little late to the party and this seems like it’s been resolved… ? I’m happy to take a look at UWP stuff (I work on the .NET team) if you see more stuff like this. Let me know.
Uau. It was fast!. Thanks a lot. I will give it a try asap.
Jiri
From: Mike-EEE notifications@github.com Sent: Saturday, November 9, 2019 8:52 AM To: ExtendedXmlSerializer/ExtendedXmlSerializer ExtendedXmlSerializer@noreply.github.com Cc: JK jkralik74@hotmail.com; Mention mention@noreply.github.com Subject: Re: [ExtendedXmlSerializer/ExtendedXmlSerializer] System.PlatformNotSupportedException with UWP and .Net Native (#269)
Alright @gr001https://github.com/gr001 I took advantage of our new repo here to update our dependency to LightInject rather than LightInject.Source. That should properly load all its UWP functionality and rule out anything on our side that might be causing it.
You can get the latest version from our new preview feed here:
https://ci.appveyor.com/nuget/extendedxmlserializer-preview
(Please be sure to enable Include prerelease in Nuget explorer.)
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ExtendedXmlSerializer/ExtendedXmlSerializer/issues/269?email_source=notifications&email_token=AGWXDX6BNDQ63TQJ6HMQP3TQSZT3BA5CNFSM4JJX3AO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDUAH2Q#issuecomment-552076266, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGWXDX5YKIJGSCGIB6IMB5TQSZT3BANCNFSM4JJX3AOQ.
ok, looks like Microsoft kills now all platform specifics and use same implementation for all platforms:
This may also help you @Mike-EEE in future to simplify code even more when .NET 5 is out.
yes, I know it was offtopic, but this is first time a .NET people was here.
@MattWhilden why does AppX/UWP not support Assembly.Load() at least for non store releases/sideloading? This raises NotSupportedException.
I have just upgraded to the latest version and it looks promissing. Thanks a lot for this fix. We rely on this serializer as a replacement of MS serializer which has some crucial limitations when used in UWP.