我正在使用MEF動態加載wcf服務。 MyInstanceProvider屬於我的服務所在的同一個物理庫。代碼在我的開發盒IIS7(64位)上工作,但在我的測試盒(32位)上拋出此異常。在我介紹MEF之前工作正常。當在服務器上託管MEF異常
我很疑惑爲什麼會發生這種情況?
public object GetInstance(InstanceContext context)
{
var lazyInstance = _container.GetExports(_serviceType, null, null).FirstOrDefault();
if (lazyInstance == null) throw new InvalidOperationException();
return lazyInstance.Value;
}
異常
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.GetInstance(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)</
編輯:
遵循了這一博客帖子獲得詳細信息: http://weblogs.asp.net/kencox/archive/2010/08/24/fed-up-with-system-data-metadata-edm-objectitemassemblyloader.aspx
這裏是我所看到的:
未能進行負載文件或程序集 'System.ServiceModel.DomainServices.EntityFramework,Version = 4.0.0.0, Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其一個 依賴關係。該系統找不到指定的文件。
我知道這是RIA服務。我確實使用這些,但不在這個位置,所以很奇怪。但不管怎麼說。爲什麼它會抱怨這個圖書館?我應該添加那些作爲參考並放入Bin文件夾? (解決方案) 好的,我在使用RIA服務(甚至不使用,只是添加引用)的解決方案中的某處 因此,不知何故,所有的MEF都需要這些RIA引用。而且,RIA服務不是.NET Framework的一部分,所以我不得不這樣做:http://blogs.msdn.com/b/deepm/archive/2010/03/15/are-you-a-hoster-and-want-to-support-ria-services.aspx
現在一切正常