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
Aucun commentaire:
Enregistrer un commentaire