System.PlatformNotSupportedException with UWP and .Net Native
See original GitHub issueHello, 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
Issue Analytics
- State:
- Created 4 years ago
- Comments:29 (15 by maintainers)
Top GitHub Comments
@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.