0

I'm trying one PoC to dynamically load assemblies (UWP Class Library's DLL) at runtime in UWP application.

With currently limitation in UWP, I can able to load the assembly if I moved them to AppX folder. After deployment in debug mode, its working great with Assembly.Load() method.

But when I try to compile and run the app in Release mode with .Net Native tool chain option enabled, its raising runtime exception and not loading the assembly.

Exception

System.IO.FileNotFoundException: Cannot load assembly 'MyUIClassLibrary.UWP'. No metadata found for ths assembly.
System.Reflection.Runtime.Assemblies.RuntimeAssembly.GetRuntimeAssembly(RuntimeAssembly
+ 0x22
 at Assembly
System.Reflection.Runtime.General.ReflectionCoreCallbacksImplementation.Load(AssemblyName, Boolean) + 0x2eb827
 at System.Reflection.Assembly.Load(Reflection.AssemblyName assemblyRef)

Code Sample

private UserControl LoadUserControl(string assemblyName)
{
    AssemblyName aName = new AssemblyName
    {
        Name = assemblyName,
        ProcessorArchitecture = ProcessorArchitecture.X86
    };

    var assembly = Assembly.Load(aName);

    Type[] tlist = assembly.GetTypes();

    return Activator.CreateInstance(tlist[0]) as UserControl;
}

...
...

//Loading UI assemblies at runtime
pivotItemOne.Content = LoadUserControl("MyUIClassLibrary.UWP");

I thought its issue with .Net Native tool chain and its avoiding the other Dlls at release mode build time. Because its working fine in debug mode.

And if I add the UWP class library project as reference to my main UWP application, then the assembly load method start working fine in both Debug and Release configuration.

For some reason, my real goal is to load the assemblies from AppX folder without referencing them in project. Loading as external assembly like in WPF application.

Please let me know am I missing something? or any workaround appreciated. Thanks in advance.

Note: My machine is running Windows 10 Fall Creator Update and using VS2017

Ramanan
  • 159
  • 1
  • 11
  • Possible duplicate of [Windows UWP - Dynamically Load Assembly In Side Loaded App](https://stackoverflow.com/questions/42237065/windows-uwp-dynamically-load-assembly-in-side-loaded-app) – Nico Zhu May 04 '18 at 06:02
  • How would you deploy this to the store? Or are you not deploying this via the store? – James Esh Dec 19 '18 at 19:05
  • This is a little late but for posterity.. In UWP I believe this behavior is because you are not allowed to load assemblies that aren't packaged up and referenced with your app and thus trusted. For better or worse it's a limitation for security purposes. Optional packages or app extensions are a possibilities to do what you want. You could also include a script engine and work that route depending on the nature of what you want to do. – b.pell Feb 02 '19 at 19:18

0 Answers0