程序集绑定重定向不起作用

Ada*_*dam 30 .net c# binding assemblies reference

我正在尝试使用以下app.config设置程序集绑定重定向:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AnalysisServices"
                          PublicKeyToken="89845dcd8080cc91" />
        <bindingRedirect oldVersion="10.0.0.0"
                         newVersion="9.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我在GAC中使用版本9.0.242.0的计算机上运行该程序,并使用指定的公钥令牌.CLR似乎甚至没有尝试重定向绑定以使用该版本.

这是我在fuslogvw.exe中得到的:

LOG: This bind starts in default load context. LOG: Using application configuration file: \Debug\AssemblyRedirectPOC.exe.Config LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config. LOG: Post-policy reference: Microsoft.AnalysisServices, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices.DLL. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices/Microsoft.AnalysisServices.DLL. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices.EXE. LOG: Attempting download of new URL /Debug/Microsoft.AnalysisServices/Microsoft.AnalysisServices.EXE. LOG: All probing URLs attempted and failed.

当我尝试将9.0.242.0版本的dll放在探测路径中时,我得到了这个:

LOG: Assembly download was successful. Attempting setup of file: \Debug\Microsoft.AnalysisServices.dll LOG: Entering run-from-source setup phase. LOG: Assembly Name is: Microsoft.AnalysisServices, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: The assembly reference did not match the assembly definition found. ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

请注意,我也尝试将重定向更改为在app.config中使用"9.0.242.0"而不是"9.0.0.0",但这不起作用,尽管我认为它不应该有任何区别.

根据我的理解,重定向绑定的重点是使用与程序构建的版本不匹配的版本.我在这里完全遗漏了什么吗?我正在尝试做什么,如果是的话,任何想法为什么它不起作用?

干杯,亚当

Shr*_*ike 29

配置xml中的任何拼写都可能是一个原因.加载器无法看到您的配置.我还有一个小时的头痛,直到我意识到错误是在模式名称中的字符"="而不是" - ":

<assemblyBinding xmlns="urn:schemas=microsoft-com:asm.v1">
Run Code Online (Sandbox Code Playgroud)

只需仔细检查所有属性名称和值.我猜"PublicKeyToken"应该是"publicKeyToken"

这应该工作:

<configuration>
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.AnalysisServices" publicKeyToken="89845dcd8080cc91" />
            <bindingRedirect oldVersion="10.0.0.0" newVersion="9.0.0.0"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

  • 错误的(用=而不是 - )*为你工作*? (23认同)
  • 添加`xmlns =“ urn:schemas = microsoft-com:asm.v1”`为我解决了这个问题。谢谢! (3认同)

Ger*_*rre 17

确保您的<configuration>标记没有名称空间属性.否则,<assemblyBinding>将忽略任何标记.

错误:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
Run Code Online (Sandbox Code Playgroud)

对:

<configuration>
Run Code Online (Sandbox Code Playgroud)

(来自/sf/answers/840785501/)

  • _This_是答案。绑定重定向被默默地忽略了,因为我的`web.config`太旧了,它具有2.0名称空间。 (2认同)
  • 头痛了 2 小时,然后解决方案就像删除 ns 一样简单。 (2认同)

Edw*_*lde 12

我遇到绑定重定向,因为在assemblyBinding元素上缺少命名空间.

正确

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="TIBCO.Rendezvous" publicKeyToken="1a696d1f90f6158a"/>
    <bindingRedirect oldVersion="1.0.0.0-1.0.3191.28836" newVersion="1.0.3191.28836"/>
  </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

不正确

注意缺少:xmlns ="urn:schemas-microsoft-com:asm.v1"

<assemblyBinding>
  <dependentAssembly>
    <assemblyIdentity name="TIBCO.Rendezvous" publicKeyToken="1a696d1f90f6158a"/>
    <bindingRedirect oldVersion="1.0.0.0-1.0.3191.28836" newVersion="1.0.3191.28836"/>
  </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)


Pat*_*tel 6

我遇到过类似的问题,将 bindingredirects 移动到 Machine.Config 是唯一有效的方法。这在我的 winform 应用程序中不是理想的解决方案,因为我将我的应用程序分发给客户。

解决方案:

确保 .config 文件位于运行应用程序的目录中。例如,如果您的 AppName 是“MyApp”,则重定向应位于应用程序目录中的“MyApp.exe.Config”文件中。

即使使用第三方 dll 的代码在我的解决方案中位于不同的 dll 中并且添加 .dll.config 没有帮助,我也必须这样做。

  • 将 bindingredirects 移动到 Machine.Config 解决了我的问题。 (2认同)

Joh*_*Fun 6

如果这对任何人有任何帮助,我遇到这个问题是因为我没有将完整版本放入 newVersion 中。即,我有newVersion="3.0.1"而不是newVersion="3.0.1.0"


saw*_*awe 5

就我而言,我必须删除

appliesTo="v2.0.05727" 
Run Code Online (Sandbox Code Playgroud)

<assemblyBinding appliesTo="v2.0.05727" xmlns="urn:schemas-microsoft-com:asm.v1">
Run Code Online (Sandbox Code Playgroud)


小智 5

当我将绑定重定向配置移至 machine.config 文件时,我的问题得到了解决。

  • 将绑定重定向移动到 Machine.Config 解决了我的问题 (2认同)