Using different versions of the same DLL in a project - c#

In my project I have to use different versions of AWSSDK dll's, in order to make this i took help of this post . and added one of my dll in to a folder named V-1 inside bin folder. Then made config changes like this
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AWSSDK" publicKeyToken="CD2D24CD2BACE800" culture="neutral" />
<codeBase version="1.4.8.2" href="V-1\AWSSDK.dll" />
<codeBase version="2.3.40.0" href="AWSSDK.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
But I still gets the error like this
Error 2 Could not load file or assembly 'AWSSDK, Version=1.4.8.2, Culture=neutral, PublicKeyToken=cd2d24cd2bace800' or one of its dependencies. The system cannot find the file specified. E:\Live \Web.config 129
At this line in web-Config
<add assembly="AWSSDK, Version=1.4.8.2, Culture=neutral, PublicKeyToken=CD2D24CD2BACE800" />
Can anyone please point-out what I am doing wrong??

Please open Solution Explorer in visual studio
Open References under the project
Select AWSSdk reference and go to its properties.
Set Specific Version = True and Copy Local = False
Make sure your output directory does not contain this dll in it.

Related

Could not load file or assembly 'System.Buffers, Version=4.0.2.0...'

I'm getting the following exception when trying to call GetDatabase method of the MongoClient class after adding a new configuration using VS config. manager:
Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I installed the latest System.Buffer nuget package v4.5.1, created dependentAssembly in my app.config and Reference in my .csproj file, but I still have the same issue. For some reason it tries to reference System.Buffer with v4.0.2. Has anyone had a similar error and how did you solve it?
Could not load file or assembly 'System.Buffers, Version=4.0.2.0…'
Solution
1) use CMD(run as Administrator ) and type
cd xxxx(xxxx\packages\System.Buffers.4.5.1\lib\netstandard2.0))
run
gacutil /i System.Buffers.dll
Then, when you finish it, please run update-package -reinstall under package manager console to reinstall the package.
2) you can try to change Version=4.0.2.0 to Version=4.0.3.0 in csproj file.
Besides, there is a similar issue you can refer to.
The easiest way is to use Nuget package manager, downgrade system.buffers to any lower version, and then upgrade it to the latest again.
In my case, I had to add the assembly reference in the web.config that was already published in the Azure App Service, inside the <configuration></configuration> tag:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I ran into this issue when adding the Azure.Storage.Blobs package to a Class Library where I was attempting to create a blob uploader client. When I added the package, it created an app.config with the correct binding redirect:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
The issue, however, is that this binding redirect needs to live in the app.config of the application, not the class library: Can a class library have an App.config file?
So, adding the binding redirect is the correct way to solve this issue. Just make sure the binding redirect is specified in the calling web/console/etc app.
Another solution: just remove references to the assembly in the Web.config files of the projects generating the exception.
The references can look like:
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
</dependentAssembly>
I ran into a similar issue, tried all the steps above. In the end, another project had an older version of the same library. Too many projects in the solution, the other reference was scrolled out of view.

How to chage default directory of .dlls creating after built with runtime and probing?

I want to move all .dlls to "lib" folder after building my application. Default program creates them in directory:
bin\Debug\netcoreapp2.2
And this is directory where I want to place my .dlls:
bin\Debug\netcoreapp2.2\lib
I create script which moves my .dlls to this folder and put it in post-built event. It works correctly.
Next, I add runtime to my app.config file like I saw in many tutorials and articles on stackoverflow.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib"/>
</assemblyBinding>
</runtime>
But, after building and starting my program, console says:
The application to execute does not exist:
app\bin\Debug\netcoreapp2.2\myDLL.dll
I want to know what's wrong with my application? How can I change the directory in which program is looking for .dlls?
I guess what you need is the codebase element in the configuration.
From documentation, If the assembly has a strong name, the codebase setting can be anywhere on the local intranet or the Internet. If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<codeBase version="2.0.0.0"
href="http://www.litwareinc.com/myAssembly.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Hope this helps.

Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0' or one of its dependencies

Recently I have started using SSMS 2017 (v17.5). In my MVC application, I am getting Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. error. Only thing changed in my application is Microsoft.SqlServer.Types version which is 14.0.0.0 now. Previously, it was 12.0.0.0.
Following are different options I have tried so far based on my research (this includes another stackoverflow articles + google) but I am getting same error.
Add <dependentAssembly> in app.config
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
Adding following line in Global.asax.cs in Application_Start method.
SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
Installing Microsoft.SqlServer.Types using NuGet.
PM> Install-Package Microsoft.SqlServer.Types
Searched for 10.0.0.0 referance in entire project but didn't find any referance.
I do have Microsoft System CLR Types for SQL Server installed for 2012, 2014, 2016 and 2017.
What am I missing here?
After spending almost a day, I was able to fix this issue. From my question above, option-1 worked for me. Only tweak was to add that in web.config instead of app.config. Hope this help someone else.
Code: web.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Microsoft.SqlServer.Types -Version 14.0.314.76 is the current version. try changing your version number. Second, check your .csproj file, Application also maintains its dependencies in .csproj file
For a net library project that have the same error, I go to NuGet packages and install this library:
Microsoft.SqlServer.Types
and its works.

Another assembly referencing the old dll

I have 2 assemblies lets call them A and B. I've assigned strong names to them and now the problem arises that assembly B is looking for the old version of assembly A.
**EDIT2: If I delete AssemblyB the problem persists so it might just be VS2008 looking for the old version? Also via fusionlog I see the following warning: wrn application configuration file binding redirects disallowed. Does this have anything to do with it? **
I get multiple errors of the same kind, here's one snippet:
You must add a reference to assembly 'AssemblyA, Version=1.2.4737.25316, Culture=neutral, PublicKeyToken=null'.
The strong named AssemblyA inside the project shows these properties:
Inside app.config I've placed this piece of code:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="AssemblyA" culture="neutral"
publicKeyToken="a22e30ac6a0edfc0"/>
<bindingRedirect oldVersion="1.2.4737.25316" newVersion="1.3.0.19440"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
But this does not work. I have access to the source of both assemblies.
EDIT: If I delete the strong named and add the old (weak named) dll to the project it will give an error asking about the strong named version
You must add a reference to assembly 'AssemblyA, Version=1.3.0.19440, Culture=neutral, PublicKeyToken=a22e30ac6a0edfc0'.
What's happening here?
Some DLL's still referred to the old (weak named) version of other DLL's. Luckily the assemblies came with the source so I had to recompile everything including a key.
After that another error came up along the lines of "The located assembly's manifest definition does not match the assembly reference"
To fix this I added the following in the app.config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no" />
<assemblyIdentity name="Assemblyname" culture="neutral" publicKeyToken="3a5628535d42dbed"/>
<bindingRedirect oldVersion="1.3.0.15233" newVersion="1.3.0.40647" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Elmah MySql Nuget Package Issue 'Could not load file or assembly'

I'm trying to add Elmah to my MVC3 project. After installing via Nuget, when I try to access elmah (via localhost:port/elmah.axd), I get an error containing this:
Could not load file or assembly 'MySql.Data, Version=6.1.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.
I've removed the mysql.data dll and added my own copy (version 6.4.4.0 - the documentation says you can override the dll provided with a newer version), but this error remains. Has anyone else encountered this?
My solution was to add this to my web.config:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity
name="MySql.Data"
publicKeyToken="c5687fc88969c44d"
culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.4.4.0" newVersion="6.4.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
This basically says to the compiler that whenever something requests a version of the MySql.Data assembly that's between versions 0.0.0.0 and 6.4.4.0, it should instead be supplied with the version 6.4.4.0 assembly instead.

Categories