【问题标题】:Binding redirect problem in .net.net 中的绑定重定向问题
【发布时间】:2009-11-17 21:05:47
【问题描述】:

我有一个名为“MyAssembly”的类库,它在内部引用 3.1.1.0 版的 a.dll、b.dll;我已经构建了输出 MyAssembly.dll 的项目。在另一个系统(框)上,我创建了一个 Web 应用程序项目并引用了 MyAssembly.dll。新系统有新版本的a.dll和b.dll 4.0.0;我在 web.config 中使用了绑定重定向,如下所示。但仍然无法编译 Web 应用程序。它说缺少程序集引用 a.dll,版本 3.1.1.0。

任何机构都可以帮助解决这个问题吗?

谢谢, 苏雷什

【问题讨论】:

    标签: .net binding assemblies


    【解决方案1】:

    这对我完全有用。注意:configuration 标签上需要 NO namespace。而且您必须在您的assemblyBinding 标记上有一个命名空间

    <assemblyBinding> Element for <runtime>

    <!-- important: no namespace -->
    <configuration> 
      <runtime>
        <!-- important, must have this namespace -->
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
          <dependentAssembly>
            <assemblyIdentity name="Strongly.Named.Assembly" publicKeyToken="xxx" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    这两个都做,否则它不会读取它。如果在这个例子中它给出了一个错误,它不能加载除了 2.0.0.0 之外的任何东西,那么它没有正确地选择配置元素。

    这也仅适用于强命名程序集。要确定某项是否具有强名称,请从 VC 命令窗口运行以下命令

    打开(开始菜单 > 所有程序 > Visual Studio > Visual Studio 工具 > Visual Studio 命令提示符)

    然后运行:

    sn -vf "path-to-assembly.dll"
    

    如果它返回它是有效的,那么它是强命名的。

    来源: http://blog.codingoutloud.com/2010/03/13/three-ways-to-tell-whether-an-assembly-dl-is-strong-named/

    【讨论】:

    • 这完全解决了我在 Web 项目中忽略绑定重定向的问题。谢谢!
    • 我爱你。你完全拯救了我的理智。我从 configuration 标记中删除了命名空间,它就起作用了!
    • 非常感谢!在 assemblyBinding 中缺少命名空间
    【解决方案2】:

    这应该可行。

    <runtime>  
     <dependentAssembly>  
       <assemblyIdentity name="MyAssembly" publicKeyToken="12233444"/>  
       <bindingRedirect oldVersion="3.1.1.0" newVersion="4.0.0.0"/>  
     </dependentAssembly>  
    </runtime>  
    

    另一个建议:从你的配置标签中删除命名空间:

    代替

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    

    试试

    <configuration>
    

    【讨论】:

    • 我做的完全一样。但没有运气。在 ide 中编译项目时给出错误提示“您是否缺少 assemblyreference a.dll 3.1.1.0
    • 配置标签不包含 xmlns 属性。没有运气
    • 它对我有用,谢谢。我的问题是为什么删除 xmlns 属性后它会起作用?
    【解决方案3】:

    您正在 Web 应用程序中使用 MyAssembly。绑定重定向将用于此程序集,而不是 MyAssembly 使用的程序集。检查 MyAssembly.dll 的清单,它应该是指 3.1.1.0 版本的 a.dll,因此显示编译器错误。参考 4.0.0.0 版本的 a.dll 构建 MyAssembly,然后在您的 Web 应用程序中使用 MyAssembly。这将起作用。

    【讨论】:

      【解决方案4】:

      试试这个方法:

      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="a.dll"
                            publicKeyToken="{put a.dll publicKeytoken here}"
                            culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-99.99.99.99"
                           newVersion="4.0.0.0"/>
        </dependentAssembly>
        <dependentAssembly>
          <assemblyIdentity name="b.dll"
                            publicKeyToken="{put b.dll publicKeytoken here}"
                            culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-99.99.99.99"
                           newVersion="4.0.0.0"/>
        </dependentAssembly>
      </assemblyBinding>
      

      另外,转到应用程序的引用,右键单击 a.dll 和 b.dll,转到属性并检查“特定版本”是否设置为 False。

      希望对你有帮助。

      【讨论】:

        猜你喜欢
        • 2011-03-15
        • 2014-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-16
        • 1970-01-01
        • 2021-01-15
        • 1970-01-01
        相关资源
        最近更新 更多