Binding redirect problem in .net

后端 未结 4 1062
有刺的猬
有刺的猬 2020-12-03 17:48

I have a class library called \"MyAssembly\" that is internally referencing a.dll, b.dll of version 3.1.1.0; I have build the project which outputed MyAssembly.dll. On a dif

相关标签:
4条回答
  • 2020-12-03 18:05

    You are using MyAssembly in your web application. The binding redirect will be used for this Assembly and not the assemblies which MyAssembly uses. Check the manifest for the MyAssembly.dll, it should be referring to the 3.1.1.0 versions of a.dll, hence the compiler error is shown. Build the MyAssembly with referring to a.dll of version 4.0.0.0 and then use the MyAssembly in your web application. This will work.

    0 讨论(0)
  • 2020-12-03 18:11

    Try this way:

    <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>
    

    Also, go to the references of your application, right click the a.dll and b.dll, go to properties and check if "Specific Version" is set to False.

    Hope it helps.

    0 讨论(0)
  • 2020-12-03 18:16

    This totally worked for me. NOTE: You need NO namespace on the configuration tag. And you MUST have a namespace on your assemblyBinding tag.

    <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>
    

    Do both of those or else it will not read it. If it is giving an error that it cannot load anything but 2.0.0.0 in this example, then it is not picking up the config elements properly.

    This also only works on strongly named assemblies. To find out if something is strongly named run the following command from the VC command window

    open (start menu > all programs > visual studio > visual studio tools > visual studio command prompt)

    Then run:

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

    If it returns that it is valid, then it's strongly named.

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

    0 讨论(0)
  • 2020-12-03 18:18

    This should work.

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

    Another suggestion: Remove the namespace from your configuration tag:

    Instead of

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

    try

    <configuration>
    
    0 讨论(0)
提交回复
热议问题