0

I have a C# class library MyLibrary in which I am referencing a sample.dll version 2.7.0. This MyLibrary is being referenced in WCF project. Which is deployed on the server.

Now on the server, I have sample.dll with the version 3.0.0 because of that I am getting referenced dll not found error as following.

Could not load file or assembly 'sample, Version=2.7.0.0, Culture=neutral, PublicKeyToken=185805eaf7302b6c' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I have found few solutions for making it version Independent like adding 'BindingRedirect' as it is a class library, I don't have web.config or app.config where I can configure 'BindingRedirect'. I have also tried setting 'Specific Version' to false but still getting the same error.

I want to make my class library such that it should work with any version of Sample dll

I tried adding following in web.config of my WCF project

 <dependentAssembly>
        <assemblyIdentity name="sample" publicKeyToken="185805eaf7302b6c" culture="neutral"/>
        <bindingRedirect oldVersion="2.7.0.0" newVersion="3.0.0.3"/>
</dependentAssembly>

But still getting the same error.

Rahul Bhati
  • 276
  • 1
  • 8
  • 1
    Could you make it explicit what the question is? – chill94 Oct 16 '19 at 06:13
  • Is it a problem to have both versions on the server _or_ update MyLibrary to version 3.0.0 of sample.dll? I wouldn't recommend going version independent. What if a version has breaking changes? Your application would become unstable and it may give you a hard time finding out why... Also, all your tests that use code from that dll would be void. – Fildor Oct 16 '19 at 06:16
  • 1
    Think you are in need of a [binding redirect](https://stackoverflow.com/questions/468825/binding-redirects). – John Wu Oct 16 '19 at 06:20
  • The server can have any future version of Sample dll. and MyLibrary should always refer to the latest version of the dll. If I don't make it version independent each time new version of sample.dll is released I will have to rebuild MyLibrary. – Rahul Bhati Oct 16 '19 at 06:22
  • 4
    @RahulBhati: No, you don't - you just need a redirect from 2.7.0 to "whatever you're actually using". Although you need to be careful - the sample DLL is using semantic versioning, then 3.0.0 is likely to have incompatibilities with 2.7.0, so your library may not work anyway. – Jon Skeet Oct 16 '19 at 06:27
  • @JonSkeet I do understand that I can face incompatibilities with the latest version of sample dll but that we can take care before releasing new version of Sample dll. I am not sure where I should write 'binding redirect' logic in class library. – Rahul Bhati Oct 16 '19 at 06:32
  • 4
    You don't write the logic in your class library. It's part of the configuration of the application. I suggest you read https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/redirect-assembly-versions – Jon Skeet Oct 16 '19 at 06:44
  • @JonSkeet I have updated the question, I have added binding redirect in my WCF project's web.config but its still not working, do I need to make any other changes? – Rahul Bhati Oct 16 '19 at 07:05
  • You may also try Reflection but obviously it is not a straight forward approach.. Go what God is suggestion a.k.a @JonSkeet ;-) – Soumen Mukherjee Oct 16 '19 at 07:10
  • "Its still not working" isn't really a clear description of what you're seeing - the same error? Something different? I'd expect the binding redirect to be generated for you automatically, to be honest. You might want to try testing this in a small console app to start with, where there are fewer moving parts. The right configuration should be applicable for a web app later. – Jon Skeet Oct 16 '19 at 07:59
  • Yes, I am still seeing the same error. I will go with your suggestion and try implementing it first in the console app. Thanks for all the help. – Rahul Bhati Oct 16 '19 at 08:45

0 Answers0