Application.LoadComponent to load component out of MEF linked assembly
I am writing a WPF application using MEF for extensibility. The core application Imports a type from an assembly that the core application knows nothing about using the MEF DirectoryCatalog. The assembly that contains the imported type lives in another dir开发者_JAVA百科ectory and has a XAML resource component embedded that I would normally be able to access using
Application.LoadComponent( new Uri( "MyAssembly;component/MyXaml.xaml" ) );
However as the assembly is linked in, doing this gets an IOException Cannot locate resource 'myxaml.xaml'
(seems strange, not complaining about not being able to find the assembly)
Anyone have any ideas?
You may be over-complicating the use of MEF and external imports. What usually happens is that you have your normal project dependencies or external dependencies in your application, and from what I can read in your post, this is working fine for you so far.
Your problem comes when you add MEF into the equation. This is probably because of the way you are bootstrapping MEF and importing these DLLs, and that I can't find out by looking at your code.
I can tell you how I do it, with sucess, on the applications I develop:
I setup everything normally, with normal project dependencies that I need for each project, then when I am bootstrapping MEF, from the main WPF application project, which has references to pretty much everything (and in my specific case it's a MefBootstrapper from Prism) what I simply do is:
public class SigepBootstrapper : MefBootstrapper
{
protected override void ConfigureAggregateCatalog()
{
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SigepBootstrapper).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(AutoPopulateExportedViewsBehavior).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(StatusBarView).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Traversals).Assembly));
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(EngineManager).Assembly));
}
...
If I wasn't using Prism I would be creating AssemblyCatalog anyway, would just set them up differently, so along some other bootstrapper I would continue to write along the lines of:
new AssemblyCatalog(typeof(SigepBootstrapper).Assembly)
精彩评论