无法加载文件或程序集 'System.Net.Http, Version=2.2.29.0'

Could not load file or assembly 'System.Net.Http, Version=2.2.29.0'

我正在开发使用 Visual Studio 2010 构建的 VSTO Outlook 加载项。我没有安装 Nuget 包管理器。当我 运行 Outlook 中的加载项出现异常时:

Could not load file or assembly 'System.Net.Http, Version=2.2.29.0'

我只是从 GitHub 克隆了原始项目。当我在调试中使用 Visual Studio 运行 它时,它工作正常。但是,一旦我发布到 setup.exe 并安装,我就会遇到上述问题。已添加对 System.Net.Http 的引用。

我的 Outlook 2007 版 app.config 文件是:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="Outlook2007.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <appSettings>
  </appSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><userSettings>
    <PluginOutlook2007.Properties.Settings>
      <setting name="TokenSettingNeed" serializeAs="String">
        <value>else imported dll settings don t work</value>
      </setting>
    </PluginOutlook2007.Properties.Settings>
  </userSettings>
</configuration>

在同一解决方案中,还有第二个针对 Outlook 2010 的项目。app.comfig 如下:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="PluginOutlook2010.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <appSettings>
  </appSettings>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <userSettings>
    <PluginOutlook2010.Properties.Settings>
      <setting name="testval" serializeAs="String">
        <value>34</value>
      </setting>
    </PluginOutlook2010.Properties.Settings>
  </userSettings>
</configuration>

然后在同一个解决方案中有第三个项目(其业务逻辑由 2007 年和 2010 年的项目与下面的 app.config 共享。System.Net.Http 命名空间实际上由第三个项目使用:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="PluginOutlookCommon.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
      // some stuff here
    </userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /></startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

我通过注释掉

设法解决了这个问题
<dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.29.0" newVersion="2.2.29.0" />
    </dependentAssembly>
</assemblyBinding>

部分在 app.config 文件中。