MEF exception when hosting on a server
I'm using MEF to dynamically load wcf service. MyInstanceProvider belongs to the same physical library where my service is. Code works on my dev box IIS7 (64bit) but throws this exception on my test box (32bit). Was working fine until I introduced MEF.
I'm puzzled on why this happening?
public object GetInstance(InstanceContext context)
{
var lazyInstance = _container.GetExports(_serviceType, null, null).FirstOrDefault();
if (lazyInstance == null) throw new InvalidOperationException();
return lazyInstance.Value;
}
Exception
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition)
at System.ComponentModel.Composition.Hosting.DirectoryCatalog.<>c__DisplayClass1.<GetExports>b__0(ComposablePartCatalog catalog)
at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore(Type type, Type metadataViewType, String contractName, ImportCardinality cardinality)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(Type type, Type metadataViewType, String contractName)
at MyInstanceProvider.GetInstance(InstanceContext context) in C:\CodeWorkspace\IDATT\Code\IDATT.Web.Services\MyInstanceProvider.cs:line 21
at MyInstanceProvider.GetInstance(InstanceContext context, Message message) in C:\CodeWorkspace\IDATT\Code\IDATT.Web.Services\MyInstanceProvider.cs:line 30
at System.ServiceModel.Dispatcher.InstanceBehavior.Ge开发者_高级运维tInstance(InstanceContext instanceContext, Message request)
at System.ServiceModel.InstanceContext.GetServiceInstance(Message message)
at System.ServiceModel.Dispatcher.InstanceBehavior.EnsureServiceInstance(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</
EDIT:
Followed this blog post to get details: http://weblogs.asp.net/kencox/archive/2010/08/24/fed-up-with-system-data-metadata-edm-objectitemassemblyloader.aspx
And here is what I see:
Could not load file or assembly 'System.ServiceModel.DomainServices.EntityFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I know this is RIA services. I do use those but not in this spot, so it's weird. But anyway. Why it's complaining about this library? Should I add those as a reference and put in Bin folder?
EDIT2(SOLUTION) Ok, somewhere in a solution I am using RIA Services (not even using, just added reference) So, somehow all of the MEF needs those RIA references. And, RIA Services not part of .NET framework so I had to do this: http://blogs.msdn.com/b/deepm/archive/2010/03/15/are-you-a-hoster-and-want-to-support-ria-services.aspx
Now everything works
I would check that WCF RIA services are installed on that machine, and then I would check to see if you are consuming any types that are (or are dependent on any types) in the System.ServiceModel.DomainServices.EntityFramework assembly.
精彩评论