Can't locate resources identified by URI '/mydll;component/subfolder/mainwindow.xaml' when loading the dll dynamically

时间:2019-01-07 13:42:53

标签: c# wpf xaml assemblies

i'm having a problem with my project. In a library that i created, i have a subfolder which contains some view and viewmodels, but since those are in a class library, i don't have an app.xaml. This has always worked without a problem.

Recently i was tasked to encrypt that dll using a tool my company bought. What this tool does, is basically to decrypt and load dinamically the assembly. Now my problem is that, when i load dinamically the class library i was mentioning before, when a window has to be launched i get the following exception

Can't locate resources identified by URI '/mydll;component/subfolder/mainwindow.xaml'

I've read that WPF has some problem when you load assemblies in this way, and a workaround is to add in the App.xaml a dummy global resources like the following:

<Application x:Class="TestWpfApp.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    StartupUri="MainWindow.xaml"> 
    <Application.Resources> 
        <SolidColorBrush x:Key="Dummy" Color="Yellow"></SolidColorBrush> 
    </Application.Resources> 
</Application>

But i don't have an App.xaml. Is there a way on how i can solve this?

Currently my setup is the following:

I have a project which has a class AssemblyLoader. This class handle the following event:

AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(currentDomain_AssemblyResolve);

So every time the framework need something from a dll that is referenced, currentDomain_AssemblyResolve is called. If the assembly needed is encrypted, i use a dll to decrypt it and return the assemblies. I'm sure that the assembly is loaded because i can hit the "business" part. It throw an exception when he call InitializeComponent() inside the window

0 个答案:

没有答案