question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.PlatformNotSupportedException with UWP and .Net Native

See original GitHub issue

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(Action1 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:closed
  • Created 4 years ago
  • Comments:29 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
MattWhildencommented, Dec 4, 2019

@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.

2reactions
MattWhildencommented, Dec 5, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UWP app throws System.PlatformNotSupportedException ...
UWP app throws System.PlatformNotSupportedException only when 'Compile with .NET Native tool chain' is enabledClosed - Lower Priority0 14.
Read more >
c# - PlatformNotSupportedException when using ...
I have an UWP (Windows 10) app which runs perfectly on debug mode (.NET Native disabled). When I am running it on release...
Read more >
Universal Windows Platform (UWP)
Hi, I've created a uwp app in visual studio, 6 weeks of app building, app run without issue in debug mode in visual...
Read more >
uwp + dapper + mysql = system.platformnotsupportedexception ...
Hi, I've created a uwp app in visual studio, 6 weeks of app building, app run without ... to check if the third-party...
Read more >
.NET Native – What it means for Universal Windows Platform ...
When you build and run in “Debug” configuration, you are running IL code against the CoreCLR packaged within your application. The .NET system...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found