Running two versions of same Dll parallel in Asp.Net - c#

I need to run two versions of same Dll to be run on my website simultaneously. So i have created a folder inside Bin and shown the second Dll path like this
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AWSSDK" culture="neutral" publicKeyToken="9f476d3089b52be3"/>
<codeBase version="2.3.40.0" href="FILE://E://Live /bin/V-2/AWSSDK.dll"/>
</dependentAssembly>
</assemblyBinding>
and added my first dll as ordinary inside bin folder. But when I try to access any function inside my AWSSDK 2.3 Dll it throws an error like this
"Could not load file or assembly 'AWSSDK, Version=2.3.41.0, Culture=neutral, PublicKeyToken=9f476d3089b52be3' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"AWSSDK, Version=2.3.41.0, Culture=neutral, PublicKeyToken=9f476d3089b52be3"
Can anyone please point out what I am doing wrong here?

This error is because may be you have different versions of ddl but there namespace will be same, and you can reference only distinct namespaces in your project.
To overcome this,
Either create different namespaces for both versions or
use strong names for assemblies.

Related

Version Independent reference in C# Class Library

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.

Application trying to reference incorrect assembly version

I have a application running on a windows server 2012 that was using Telerik.Web.UI.dll version 2014.1.403.45.
During the latest deployment the Telerik dll under /bin folder got updated with 2015.1.401.40.
Because of new dll some functionality stopped working.
When i replace the dll on server with older version i get following error
Parser Error Message: Could not load file or assembly 'Telerik.Web.UI, Version=2015.1.401.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4' or one of its dependencies.
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I also tried to assembly binding
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Telerik.Web.UI" publicKeyToken="121fae78165ba3d4" culture="neutral"/>
<bindingRedirect oldVersion="2015.1.401.40" newVersion="2014.1.403.45"/>
<assemblyIdentity name="Microsoft.WindowsAzure.Storage" publicKeyToken="31bf3856ad364e35" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.1.0.4" newVersion="2.1.0.4"/>
</dependentAssembly>
</assemblyBinding>
I am still getiing the same error.
Is there any way to handle this without deplying the entire code again?
i got this type of issue, but in different case(in Unit Testing). for that I cleared the Bin. then did a build. then issue resolved for me.
Maybe there is a way, but I would redeploy. Build it again with the reference to the older version. That's the safest way and the best way to make sure all references point to the same assembly.
To be absolutely sure about the right references, set the dll to copy to local is true, and copy and replace it with the one on your server.

Error while loading assembly on separated AppDomain

My application creates multiple AppDomains and I manually configure the binding redirects via the SetConfigurationBytes method. I grab the config file, check for all assemblies installed on the private folder and then set the assemblyRedirect as on the example below. This is to ensure that I'll always use the shipped version of a given assembly:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.2.18.0" />
</dependentAssembly>
However, when an assembly being loaded in a different AppDomain depends upon the System.Net.Http assembly, I get the following error: System.IO.FileLoadException: Loading this assembly would produce a different grant set from other instances.
There's two possible ways I've saw to solving this: either by removing the <dependentAssembly> element on the config for this DLL, or to add this assembly on the GAC.
I didn't like any of this because the first may cause problems with other assemblies and the second relies on the GAC, which some of my clients don't like.
Anyone have a different idea on how to solve this?
Thanks in advance.

How to add dependent assembly without editing webConfig?

So according to my boss we are not allowed to edit the webConfig (I know weird right?). I've added nuGet packages for Microsoft.Owin and other dependent packages. These packages made changes to the webConfig by dependent assemblies to a runtime node.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
</dependentAssembly>
...etc...
My question is can I remove the runtime node and its contents but still have the same functionality without removing or changing code? If I remove the node now I get the following error:
Could not load file or assembly 'Microsoft.Owin, Version=2.1.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)
Whenever you see a bindingRedirect element in your application config file, this means that you have some inconsistency between the versions of the assemblies you are using. The NuGet system automatically detects this inconsistency and adds the binding redirect to ensure that at least you don't get compile time errors. Of course at runtime you might have problems with it because the assembly that depends on the older version of Microsoft.Owin might not work as expected with the one you are redirecting to: especially if there are some breaking changes and it attempts to call a method that no longer exists. The sole fact that you got a binding redirect added in your config file when installing the NuGet means that you might a problem and this problem might manifest only under certain specific circumstances at runtime.
So basically I would start by looking at all dependent assemblies that are references in this project along with their dependencies and try to see where this inconsistency of the versions come from. Then try to eliminate it by finding a newer version of this assembly that works with the latest Microsoft.Owin.

Could not load file or assembly Telerik.Web.UI in ASP.NET

I had telerik version 2012.2.607.35 When I update it to version 2015.2.623.45
I got this error:
Could not load file or assembly 'Telerik.Web.UI,
Version=2012.2.607.35, Culture=neutral, PublicKey
Token=121fae78165ba3d4' or one of its dependencies. The located
assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
I replaced all reference telerik to version 2015.2.623.45 in project references but the error exist yet.
While the assembly binding redirect is a way to solve this, as suggested by the answer, I would advise you to find the fully qualified assembly reference and make it non-fully qualified. It is likely to be a Register directive in the web.config or in a user control. Doing that will make future updates easier, otherwise you will get the same error the next time you upgrade unless you also update the bindingRedirect.
you should define assembly in web.config file
<dependentAssembly>
<assemblyIdentity name="YourDllFile" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-YourDllFileVersion" newVersion="YourDllFileVersion" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Telerik.Web.UI" publicKeyToken="121fae78165ba3d4" />
<bindingRedirect oldVersion="1.0.0.0-2015.2.600.45" newVersion="2015.2.623.45" />
</dependentAssembly>
I had a similar problem. I checked the version of the .dll in the bin folder on my website and the version throwing the error. Since the code where the error was being thrown was not my own, I realised the version of the .dll was a dependency of 3rd party code. As it turns out the .dll in my bin had been overwritten with an older version.
Solution was to put the correct version of the .dll in the bin folder (since this was installed with the application initially) seems an update failed to install the newer version.

Categories