2012-03-26 111 views
5

我有一個MEF應用程序,在本地運行時效果很好,但在遠程調用網絡共享時無效。當應用程序在網絡上共享時,MEF的組成

我正在使用Assembly.LoadFrom來避免UNC問題,但是看到所有的DLL都位於exe旁邊,我並不認爲這會是問題,但我試過任何方法。

在查看msdn後,我還修復了ConfigurationManager.GetSection問題,這似乎是.NET 4權限的常見問題。

我允許<loadFromRemoteSources enabled="true"/>在配置文件中。所以我不確定問題出在哪裏。

編輯: ProductDispatcher中的異常在catalog.Parts中是明確的。

的代碼建立容器和目錄:

var catalog = new AggregateCatalog(); 

var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); 

foreach (string file in Directory.GetFiles(dir, "XXX*.dll")) 
{ 
    var assembly = Assembly.LoadFrom(file); 
    catalog.Catalogs.Add(new AssemblyCatalog(assembly)); 
} 

var container = new CompositionContainer(catalog); 
var batch = new CompositionBatch(); 
batch.AddPart(this); 
container.Compose(batch); 

導入是(我曾嘗試使公共):

[ImportMany(typeof(IEntityTypeDispatcher))] 
private IEnumerable<IEntityTypeDispatcher> Dispatchers { get; set; } 

一個出口的一個例子是:

[Export(typeof(IEntityTypeDispatcher))] 
internal class ContactDispatcher : EntityTypeDispatcher<Contact> 

我得到的異常錯誤是:

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information. 

1) Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 

Resulting in: An exception occurred while trying to create an instance of type 'XXX.XXX.Dispatch.ProductDispatcher'. 

Resulting in: Cannot activate part 'XXX.XXX.Dispatch.ProductDispatcher'. 
Element: XXX.XXX.Dispatch.ProductDispatcher --> XXX.XXX.Dispatch.ProductDispatcher --> AssemblyCatalog (Assembly="XXX.XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") 

Resulting in: Cannot get export 'XXX.XXX.Dispatch.ProductDispatcher (ContractName="XXX.XXX.Dispatch.IEntityTypeDispatcher")' from part 'XXX.XXX.Dispatch.ProductDispatcher'. 
Element: XXX.XXX.Dispatch.ProductDispatcher (ContractName="XXX.XXX.Dispatch.IEntityTypeDispatcher") --> XXX.XXX.Dispatch.ProductDispatcher --> AssemblyCatalog (Assembly="XXX.XXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") 

Resulting in: Cannot set import 'XXX.XXX.Dispatch.DispatcherRepository.Dispatchers (ContractName="XXX.XXX.Dispatch.IEntityTypeDispatcher")' on part 'XXX.XXX.Dispatch.DispatcherRepository'. 
Element: XXX.XXX.Dispatch.DispatcherRepository.Dispatchers (ContractName="XXX.XXX.Dispatch.IEntityTypeDispatcher") --> XXX.XXX.Dispatch.DispatcherRepository 
(System.ComponentModel.Composition.CompositionException) 

    at System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition atomicComposition) 
    at System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.Compose(CompositionBatch batch) 
    at System.ComponentModel.Composition.Hosting.CompositionContainer.Compose(CompositionBatch batch) 
    at XXX.XXX.Dispatch.DispatcherRepository.LoadDispatchers() in D:\Workspaces\XXX\Branches\Dev1\XXX.XXX\XXX.XXX\Dispatch\DispatcherRepository.cs:line 71 
    at XXX.XXX.Dispatch.DispatcherRepository.get_Instance() in D:\Workspaces\XXX\Branches\Dev1\XXX.XXX\XXX.XXX\Dispatch\DispatcherRepository.cs:line 34 
    at XXX.XXX.Dispatch.DispatcherRepository.GetDispatchers() in D:\Workspaces\XXX\Branches\Dev1\XXX.XXX\XXX.XXX\Dispatch\DispatcherRepository.cs:line 21 
    at XXX.XXX.Dispatch.Dispatcher.get_Instance() in D:\Workspaces\XXX\Branches\Dev1\XXX.XXX\XXX.XXX\Dispatch\Dispatcher.cs:line 30 
    at XXX.XXX.Broker..ctor() in D:\Workspaces\XXX\Branches\Dev1\XXX.XXX\XXX.XXX\Broker.cs:line 52 

似乎是MEF在部分信任場景中不能很好地工作。有什麼我需要做的,以確保一切都在充分信任下運行?

+0

我有我的項目同樣的問題,但我很遺憾始終沒能解決這個問題。 :( – eandersson 2012-03-29 14:01:28

回答

3

儘管您已啓用「從遠程源加載」,但可能會發生這種情況,因爲這些文件可能對它們仍有限制。

NTFS支持將元數據應用於備用數據流(ADS)中的文件的功能。這將包括區域信息(例如互聯網區域等)。

這可能是導致網絡位置文件出現問題的原因,它們可能會歸入Internet區域,因此仍有可能被阻止。

看看這篇文章,看看這是否會解決這個問題爲您:http://mikehadlow.blogspot.co.uk/2011/07/detecting-and-changing-files-internet.html

相關問題