This code looks correct, in principle; the problem is in the assembly being loaded.
One line which is a suspect is "
CreateInstance
". It would create instance of some type, which may have not the same name as the entry point. You may want to look my very robust design of working with plug-ins and finding custom entry point instead. I describe its skeleton here:
Create WPF Application that uses Reloadable Plugins...[
^],
AppDomain refuses to load an assembly[
^].
Please ignore everything related to re-loadable stuff and Application Domain. You probably only need to load your plug-in assembly only once, so this is not a problem at all.
The exception "Exception has been thrown by the target of an invocation" is very typical for invocation of something which will through exception.
To find out what's wrong, create the assembly to be loaded on disc and try to reference this assembly in the some other project directly and than call its implementation of entry point; in this way it will be shown what's wrong more explicitly under debugger.
Putting a WPF assembly using XAML in a library is not so trivial task. If the assembly you're referencing it trying to create and run the WPF application, it should contain the entry point like this:
MyApplication application = new MyApplication();
application.MainWindow = new MyMainWindow();
application.MainWindow.Icon =
application.MainWindow.Show();
application.Run();
Is that what you are doing? I recently developed a system where WPF application is run in the class library compiled in a separate assembly; it worked out perfectly.
—SA