MEF 的 ClickOnce 问题
我有一个相当复杂的 wpf 应用程序,它使用 MEF 加载可选组件。这对于标准安装程序来说效果很好。
我试图使用 ClickOnce 部署来实现此功能,当应用程序假设导入可能的 MEF 组件时,我收到一个异常:
System.ComponentModel.Composition.CompositionException:组合产生了单个组合错误。下面提供了根本原因。查看 CompositionException.Errors 属性以获取更多详细信息。
1) 远程服务器返回错误:(404) 未找到。
导致:尝试创建“Client.Map.GeneralXamlMap.GeneralMapViewModel”类型的实例时发生异常。
结果:无法激活部分“Client.Map.GeneralXamlMap.GeneralMapViewModel”。 元素:Client.Map.GeneralXamlMap.GeneralMapViewModel --> Client.Map.GeneralXamlMap.GeneralMapViewModel --> AssemblyCatalog (Assembly="Client.Map.GeneralXamlMap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
导致:无法导出 'Client.Map.GeneralXamlMap.GeneralMapViewModel (ContractName="Client.Core.Core. Map.IMapViewModel")' 来自“Client.Map.GeneralXamlMap.GeneralMapViewModel”部分。 元素:Client.Map.GeneralXamlMap.GeneralMapViewModel (ContractName="Client.Core.Core.Map.IMapViewModel") --> Client.Map.GeneralXamlMap.GeneralMapViewModel --> AssemblyCatalog (Assembly="Client.Map.GeneralXamlMap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
我已检查本地文件夹,并且带有导出的 dll 按预期位于该文件夹中。用于查找导出的代码是这样的:
public static IMapViewModel FindMap(string exportMetadataMapName)
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog("Client.Map.GeneralXamlMap.dll"));
CompositionContainer container = new CompositionContainer(catalog);
MapFactory f = new MapFactory();
container.ComposeParts(f);
foreach (Lazy<IMapViewModel, IMapMetaData> item in f.maps)
{
if (item.Metadata.Name.Equals(exportMetadataMapName))
{
return item.Value;
}
}
return null;
}
有什么想法吗?
更新:我不知道为什么我之前没有看到这个,但我尝试加载的组件是一个从 URL 加载图像的 wpf 用户控件。当我删除该网址时,它就可以工作了。这可能与安全相关吗? Click Once 安装程序是完全信任的。
I've got a fairly complex wpf application that use MEF to load optional components. This works just fine with a standard installer.
I'm trying to get this working using ClickOnce deployment and when the application is suppose to import possible MEF components, I get an exception :
System.ComponentModel.Composition.CompositionException: The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) The remote server returned an error: (404) Not Found.
Resulting in: An exception occurred while trying to create an instance of type 'Client.Map.GeneralXamlMap.GeneralMapViewModel'.
Resulting in: Cannot activate part 'Client.Map.GeneralXamlMap.GeneralMapViewModel'.
Element: Client.Map.GeneralXamlMap.GeneralMapViewModel --> Client.Map.GeneralXamlMap.GeneralMapViewModel --> AssemblyCatalog (Assembly="Client.Map.GeneralXamlMap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
Resulting in: Cannot get export 'Client.Map.GeneralXamlMap.GeneralMapViewModel (ContractName="Client.Core.Core.Map.IMapViewModel")' from part 'Client.Map.GeneralXamlMap.GeneralMapViewModel'.
Element: Client.Map.GeneralXamlMap.GeneralMapViewModel (ContractName="Client.Core.Core.Map.IMapViewModel") --> Client.Map.GeneralXamlMap.GeneralMapViewModel --> AssemblyCatalog (Assembly="Client.Map.GeneralXamlMap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")
I've checked the local folder, and the dll with the export is in the folder as expected. The code used to find the export is this :
public static IMapViewModel FindMap(string exportMetadataMapName)
{
var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog("Client.Map.GeneralXamlMap.dll"));
CompositionContainer container = new CompositionContainer(catalog);
MapFactory f = new MapFactory();
container.ComposeParts(f);
foreach (Lazy<IMapViewModel, IMapMetaData> item in f.maps)
{
if (item.Metadata.Name.Equals(exportMetadataMapName))
{
return item.Value;
}
}
return null;
}
Any ideas ?
Update: I don't know why i didn't see this before, but the component I'm trying to load is a wpf usercontrol that loads an image from a URL. When I remove that url it works. Can this be security related ? The Click Once installer is a full trust.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,所以我终于找到了。我将为感兴趣的人留下一个快速解决方案。
经过一番挖掘后,我发现问题不是 MEF 实现造成的,而是 MEF 组件的实现错误。其中一个组件合并了一个资源字典运行时,并且该字典是使用 URI“pack://siteoforigin...”加载的。当使用 ClickOnce 部署应用程序时,源站点是 Web 服务器,然后应用程序对web服务器获取uri中的文件,导致404错误。
OK, so i finally found it. I'll leave a quick solution for anyone interested.
After a bit of digging around I found that it wasn't the MEF implementation that caused the problem, but a MEF component with a faulty implementation. One of the components merge a resource dictionary runtime and that dictionary was loaded using the URI "pack://siteoforigin..." When the application was deployed using ClickOnce, site of origin was the webserver and the application then did a httpget to the webserver to get the file in the uri, resulting in a 404 error.