How to load/import dll with MEF out of metro app?

2019-07-25 17:54发布

问题:

I've trying to write a extendable metro app using MEF. I got it working with a local extension (inside of the current assembly). Now I want to load a external dll. The DirectoryCatalog seems to be not present in .net 4.5. So I tried to use ApplicationCatalog but I got the following error while calling SatisfyImportsOnce: Assembly.LoadFrom is not supported in AppX..

Here's me code:

var catalog = new AssemblyCatalog(GetType().GetTypeInfo().Assembly);
ApplicationCatalog catApp = new ApplicationCatalog();
AggregateCatalog cat = new AggregateCatalog(catalog, catApp);
_compositionService = cat.CreateCompositionService();
_compositionService.SatisfyImportsOnce(this);

Any suggestions what's going wrong?

I've placed the dll in the Appx directory and run VS11 Beta as administrator.

回答1:

Your external library reaches outside the allowed sandbox of Metro. The .NET framework in in the Metro environment is limited, similar to the WP7 or Micro Framework. There are a lot of things cut. If your external DLL isn't built using those constrained libraries, then the compiler will disallow its use.



回答2:

I talked to some supporter in the MEF forums and he confirms that ApplicationCatalog could not be used out of a metro app. So this question is not solveable but could be closed. Source Thread