MEF 的 ClickOnce 问题

发布于 2024-11-08 10:57:22 字数 1918 浏览 5 评论 0原文

我有一个相当复杂的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼泪 2024-11-15 10:57:22

好的,所以我终于找到了。我将为感兴趣的人留下一个快速解决方案。

经过一番挖掘后,我发现问题不是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文