我有一个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 :(得分:3)
虽然您已启用“从远程源加载”,但这可能会发生,因为文件可能仍然有限制。
NTFS支持将元数据应用于备用数据流(ADS)中的文件的功能。这将包括区域信息(例如互联网区域等)。
这可能是导致网络位置文件出现问题的原因,它们可能会在Internet区域中进行分类,因此仍有可能被阻止。
查看此文章,看看是否可以解决此问题:http://mikehadlow.blogspot.co.uk/2011/07/detecting-and-changing-files-internet.html