big*_*7bb 5 .net mef composition
我有一个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);
Run Code Online (Sandbox Code Playgroud)
导入是(我试过公开):
[ImportMany(typeof(IEntityTypeDispatcher))]
private IEnumerable<IEntityTypeDispatcher> Dispatchers { get; set; }
Run Code Online (Sandbox Code Playgroud)
导出的一个例子是:
[Export(typeof(IEntityTypeDispatcher))]
internal class ContactDispatcher : EntityTypeDispatcher<Contact>
Run Code Online (Sandbox Code Playgroud)
我得到的异常错误是:
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
Run Code Online (Sandbox Code Playgroud)
似乎MEF在部分信任场景中不能很好地工作.有什么我需要做的,以确保一切都在完全信任下运行?
尽管您已启用“从远程源加载”,但可能会发生这种情况,因为文件可能仍然受到限制。
NTFS 支持将元数据应用到备用数据流 (ADS) 中的文件的功能。这将包括区域信息(例如互联网区域等)。
这可能是导致网络文件出现问题的原因,它们可能被分类在 Internet 区域中,因此仍然可能被阻止。
查看这篇文章,看看这是否可以解决您的问题:http://mikehadlow.blogspot.co.uk/2011/07/detecting-and-changing-files-internet.html
| 归档时间: |
|
| 查看次数: |
723 次 |
| 最近记录: |