1
votes

I’m developing an UWP that works perfect in Debug mode, when I compiled it in Release Mode it compiles without an error, but when I run the app, I have a process the uses a function in a .Net Standard 2.0 library that throws a System.IO.FileNotFoundException System.Security. No metadata found for this assembly.

This is my rd.xml

<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
  <Application>
    <!--
      An Assembly element with Name="*Application*" applies to all assemblies in
      the application package. The asterisks are not wildcards.
    -->
    <Assembly Name="*Application*" Dynamic="Required All" />

    <!-- Add your application specific runtime directives here. -->

    <Assembly Name="System.Runtime" Dynamic="Required All" />
    <Assembly Name="System.Security" Dynamic="Required All" />

    <Type Name="Windows.Foundation.TypedEventHandler{Microsoft.UI.Xaml.Controls.NavigationView,Microsoft.UI.Xaml.Controls.NavigationViewItemInvokedEventArgs}" MarshalObject="Public" />

    <Type Name="Microsoft.UI.Xaml.Controls.NavigationView">
      <Event Name="ItemInvoked" Dynamic="Required"/>
    </Type>

    <Type Name="System.Configuration.AppSettingsSection" Serialize="Required Public" />
  </Application>
</Directives>

And the line that throws the error is this one.

            Assembly System_Security_Assembly = Assembly.Load("System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

Even though this one works fine.

Assembly cripXmlAssembly = Assembly.Load("System.Security.Cryptography.Xml");

I’ve read about adding a directive to an RD.xml files but I think this applies to UWP, and in this case the Exception is being thrown by the Net Standard dll. Could someone please shed some light on this?

Here is a repro.

enter link description here

1
Yes, this is exactly why you need to test the .NETNative build and edit rd.xml. You can't get specific advice when you don't show anything.Hans Passant
Thanks for your answer I update the question.Michael
I create a blank UWP project and a Class Library(.Net Standard 2.0), when I add the line Assembly.Load("System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); in Class Library and call it, it works well. So what architecture are you using? If you create a blank app to use it, will the same error occur? And can you provide a simple sample that can be reproduced?Faywang - MSFT
I attach a sample tha reproduces the issue link . Did you try in realese mode? I'm using x64 as a target.Michael

1 Answers

0
votes

By discussion, we found that dynamic loading of assemblies is not supported in CoreRT(which is the runtime used when an app is compiled in Release with .NET native toolchain):

​ We know that .NET native is used for UWP apps when building in Release mode.​

​ From this document:​

.NET Native uses CoreRT in conjunction with the UTC compiler to provide native compilation for UWP apps​.

​ And from this thread :​ ​

Unsupported features: Dynamic loading (e.g. Assembly.LoadFile), dynamic code generation (e.g. System.Reflection.Emit), Windows-specific interop (e.g. COM, WinRT)​

Here also mentions currently this is not possible in CoreRT.

In fact, the only assemblies that can be "loaded" are those that are statically linked into the running native process.