简体   繁体   中英

Compile C# library projects requiring bindingRedirect

I am referencing a third party dll that requires a bindingRedirect in the app.config file as follows:

<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.1.10.0" newVersion="2.1.10.0" />
      </dependentAssembly>
      ...
    </assemblyBinding>
</runtime>

I am trying to reference this in a C# library project. The library will be shared between a WCF project and MVC project. However the my library cannot find the references anymore. I get the following warning:

The primary reference "ThirdParty" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "ThirdParty" or retarget your application to a framework version which contains "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

I have added an app.config file to the library with the required bindingRedirect. However this configuration is ignored.

I have also tried converting the library to a console application. In this case it compiles perfectly and works.

How does one compile a library project that requires assemblyBinding to do a bindingRedirect?

You are getting a compile-time error because the third party DLL exposes types from System.Net.Http. You simply need to add the reference to the System.Net.Http assembly to resolve it.

Do so by using Nuget. You want the Microsoft HTTP Client Libraries package .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM