You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移VSTO插件安装程序至WiX遇System.Memory加载失败求助

解决WiX安装Office VSTO插件时System.Memory版本不匹配问题

问题场景

将Office VSTO插件的安装程序从Windows Installer迁移至WiX后,启动Outlook时触发以下错误:

Could not load file or assembly 'System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Windows Installer安装的插件可正常运行,即使未修改插件代码,WiX安装包仍会触发该错误。经排查,核心原因是WiX安装后插件无法找到nophihs.dll.config文件,导致程序集版本重定向失效——实际部署的System.Memory版本为4.0.1.2,但依赖它的AngleSharp NuGet包请求的是4.0.1.1。

解决方案

1. 确保WiX项目正确包含config文件

在WiX项目中,需要将nophihs.dll.config作为组件添加,并确保其安装路径与插件DLL一致,同时包含到对应的Feature中:

<ComponentGroup Id="AddinComponents" Directory="INSTALLFOLDER">
    <!-- 插件DLL组件 -->
    <Component Id="MyAddinDll" Guid="*">
        <File Source="$(var.MyAddinProject.TargetDir)nophihs.dll" KeyPath="yes" />
    </Component>
    <!-- Config文件组件 -->
    <Component Id="MyAddinConfig" Guid="*">
        <File Source="$(var.MyAddinProject.TargetDir)nophihs.dll.config" 
              DestinationFolder="INSTALLFOLDER" 
              KeyPath="yes" />
    </Component>
</ComponentGroup>

<!-- 在Feature中引用组件组 -->
<Feature Id="MainFeature" Title="Main Feature" Level="1">
    <ComponentGroupRef Id="AddinComponents" />
</Feature>

2. 验证config文件的版本重定向配置

检查nophihs.dll.config中的运行时配置,确保针对System.Memory的版本重定向规则正确:

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Memory" 
                                  publicKeyToken="cc7b13ffcd2ddd51" 
                                  culture="neutral" />
                <!-- 覆盖从0到当前部署版本的所有旧版本 -->
                <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" 
                                 newVersion="4.0.1.2" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

3. 检查安装路径与权限

  • 确认WiX中定义的INSTALLFOLDER路径与原Windows Installer版本一致,避免文件部署到错误目录;
  • 确保插件安装目录(如C:\Program Files\YourAddinName\)具备读取权限,防止Outlook加载插件时无法访问config文件。

4. 清理并重新构建

  • 删除WiX项目的输出目录和临时构建文件,重新生成安装包;
  • 安装前彻底卸载旧版本插件,避免残留文件干扰新版本的部署。

内容的提问来源于stack exchange,提问作者RAMe0

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 00:53:11