Resolve "System.Reflection.MissingMetadataException" when running UWP app in release mode

I had been seen an issue "System.Reflection.MissingMetadataException" when running a UWP app in release mode. It was failure at the code: public static MobileServiceClient MobileService = new MobileServiceClient(""); I turn on the "Compile with .NET Native tool chain" option in property of project settings as below screen shot, and then run the app in Debug mode.



This time it throws more details of error "'Microsoft.WindowsAzure.MobileServices.PlatformInformation' is missing metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859". I went to that link of page and also search it in google. 

Now knew it was caused by the  ".NET Native does not presently have a just-in-time compiler to compile the pieces that are missing, everything that can be accessed at runtime needs to be known at the time of compilation". The reflection of mobile service can not be determined statically at the time of compilation, and so I need to do something in the default.rd.xml according to page https://docs.microsoft.com/en-us/dotnet/framework/net-native/runtime-directives-rd-xml-configuration-file-reference. File "default.rd.xml" is under "Property" folder of the project.

In my case, the change as below:
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Namespace Name="" Activate="Required Public" />
<Type Name="Microsoft.WindowsAzure.MobileServices" Dynamic="Required All" />
   <Type Name="Microsoft.WindowsAzure.MobileServices.PlatformInformation" Dynamic="Required All" />
  <Namespace Name="System.Private.Reflection.Core" Serialize="Required All" />
  <Type Name="System.EventHandler" Dynamic="Required All" />
</Application>
</Directives> 

After added above changes, the issue was gone and I am able to run the app in release mode now!

Comments

Popular posts from this blog

Top JavaScript courses helping you develop SPFx webPart with ReactJS and AngularJS

SharePoint 2013 error - "Application error when access /_vti_bin/client.svc"

Enable the Microsoft Power BI report file type (.pbix) in SharePoint Search