MEF Composition Import Issue
-
2011年12月8日 15:19
I have a MEF composition question. In my dev environment I am able to use this code to import parts:
var dirCatalog = new DirectoryCatalog(path, "MyCompany.*.dll"); var container = new CompositionContainer(dirCatalog); container.SatisfyImportsOnce(this);
However, when I deploy to a test server that doesn't work. I get composition errors. The only way I have found to make it work is to explicitly load the dlls that have exports.var catalog = new AggregateCatalog(); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFrom(Path.Combine(path, "MyCompany.Services.AppServer.Modelling.dll")))); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFrom(Path.Combine(path, "MyCompany.IFS.AppServer.Dispatchers.dll")))); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFrom(Path.Combine(path, "MyCompany.Services.AppServer.Service.dll")))); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFrom(Path.Combine(path, "MyCompany.IFS.Common.InstrumentService.Proxy.dll")))); catalog.Catalogs.Add(new AssemblyCatalog(Assembly.LoadFrom(Path.Combine(path, "MyCompany.IFS.Common.InstrumentPropertyService.Proxy.dll")))); var container = new CompositionContainer(catalog); container.SatisfyImportsOnce(this);
Why am I not able to use the wildcard to specify which assemblies to search for exports? What am I missing?This code is in a custom service host factory used for starting a WCF service hosted in IIS. Not sure that it matters...
Thanks!
GregP
全部回复
-
2011年12月8日 16:29What are the errors?
JP Cowboy Coders Unite! -
2011年12月8日 17:03
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
System.Reflection.RuntimeModule.GetTypes() +4
System.Reflection.Assembly.GetTypes() +78
System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog() +113
System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition) +10
System.ComponentModel.Composition.Hosting.<>c__DisplayClass1.<GetExports>b__0(ComposablePartCatalog catalog) +17
System.Linq.<SelectManyIterator>d__14`2.MoveNext() +238
System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +224
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports) +39
System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition) +35
System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +139
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports) +39
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports) +28
System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition) +45
System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports) +39
System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition) +35
System.ComponentModel.Composition.Hosting.ImportEngine.TryGetExports(ExportProvider provider, ComposablePart part, ImportDefinition definition, AtomicComposition atomicComposition) +47
System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComposition) +177
System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part) +479
System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager, ComposablePart part, Boolean shouldTrackImports) +237
System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImportsOnce(ComposablePart part) +113
System.ComponentModel.Composition.Hosting.CompositionContainer.SatisfyImportsOnce(ComposablePart part) +27
System.ComponentModel.Composition.AttributedModelServices.SatisfyImportsOnce(ICompositionService compositionService, Object attributedPart) +41
Starkey.IFS.AppServer.WebHost.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +337
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1461
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +44
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +651[ServiceActivationException: The service '/IfsAppService/ifsappservice.svc' cannot be activated due to an exception during compilation. The exception message is: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information..]
System.Runtime.AsyncResult.End(IAsyncResult result) +688590
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190
System.ServiceModel.Activation.ServiceHttpModule.EndProcessRequest(IAsyncResult ar) +310694
System.Web.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar) +94
GregP

