Could not load file or assembly 'System.Data' - c#

I receive this error:
Could not load file or assembly 'System.Data' or one of its dependencies
This is my code in Web.Config.
<add assembly="System.Data" />
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Data' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
Could you help me out to figure out what I'm doing wrong? Thanks

Related

Could not load file or assembly 'Microsoft.Data.SqlClient' in .NET standard Library

I've created a .NET standard library 2.0 which uses Microsoft.Data.SqlClient Version=1.12.20106.1. I'm referring to this library in the console application (.NET Framework 4.7.2). While making call, I'm getting the error shown below, even though I've added an assembly reference. Can anyone help please?
Could not load file or assembly 'Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5' or one of its dependencies. The system cannot find the file specified.":"Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5"}
Chances are that in the full error you will see something like
The located assembly's manifest definition does not match the
assembly reference. (Exception from HRESULT: 0x80131040)
When I experience a similar problem and run a unit test in the debugger then I see this sort of thing in the unit test output Pre-bind state information
Pre-bind state information
LOG: DisplayName = Microsoft.Data.SqlClient, Version=2.0.20168.4, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5
(Fully-specified)
LOG: Appbase = file:///C:/Dev2/MyApp/UnitTests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : MyApp, Version=1.0.0.2, Culture=neutral, PublicKeyToken=c.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Dev2\myapp\UnitTests.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 2.0.20168.4 redirected to 1.12.20106.1.
LOG: Post-policy reference: Microsoft.Data.SqlClient, Version=1.12.20106.1, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5
LOG: Attempting download of new URL file:///C:/Dev2/MyApp/UnitTests/bin/Debug/Microsoft.Data.SqlClient.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
The issue is an assembly binding issue the answer here may help. Don't worry that it mentions VB6 the actual issue is independent of that.
This answer is only useful if your netstandard2.0 library has referenced Microsoft.Data.SqlClient as a NuGet package and the referred assembly is not copied over on build.
You may have to use dotnet publish to have the Microsoft.Data.SqlClient assembly copied. It's something that I stumbled upon lately and that I had to fix using a custom resolver. You shouldn't use that resolver but you should check if publishing your application and library helps the issue.

SignalR not working in ASP .Net 5 RC-1

I can't seem to get SignalR 3 working on ASP .Net 5 RC-1 upgrading from Beta8. I tried the latest RC1 package for SignalR but had the following problem. I tried the "Microsoft.AspNet.SignalR.Server": "3.0.0-rc1-15810" package
services.AddSignalR();
is causing the following error:
The type 'IServiceCollection' is defined in an assembly that is not
referenced. You must add a reference to assembly
'Microsoft.Extensions.DependencyInjection.Abstractions,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
and app.UseSignalR();
is causing this one:
The type 'IApplicationBuilder' is defined in an assembly that is not
referenced. You must add a reference to assembly
'Microsoft.AspNet.Http.Abstractions, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'.
When I switch to the "Microsoft.AspNet.SignalR.Server": "3.0.0-rc2-15909" package I get a runtime error:
An exception of type 'System.TypeLoadException' occurred in
mscorlib.dll but was not handled in user code
Additional information: Could not load type
'Microsoft.AspNet.Http.RequestDelegate' from assembly
'Microsoft.AspNet.Http.Abstractions, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=adb9793829ddae60'.
I've just tested this, and it looks like a reference to the aspnetmaster myget feed is required, even though this is not mentioned in the installation docs.
Prior to including aspnetmaster I could only resolve Microsoft.AspNet.SignalR.Server 3.0.0-rc1-15810 either directly or by specifying rc1-*, which does not build against rc1-final. Including aspnetmaster gives access to rc1-final.
If you're using Visual Studio 2015, go to Tools > Options > Nuget Package Manager > Package Sources and add a new feed called whatever you like but with source set to https://www.myget.org/F/aspnetmaster/api/v3/index.json.
If you're not using VS2015, or you don't want to edit your machine-wide config, add/edit NuGet.config in your solution root directory to include a package source as follows;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="aspnetmaster" value="https://www.myget.org/F/aspnetmaster/api/v3/index.json" />
</packageSources>
</configuration>
Use MyGet sources for "Microsoft.AspNet.SignalR.Server": "3.0.0-rc1-final"
Here related answer, that can be helpful:
Can't find Microsoft.AspNet.SignalR.Server 3.0.0-beta7
For anyone who is looking at this page now, the aspnetmaster feed has removed "Microsoft.AspNet.SignalR.Server": "3.0.0-rc1-final"

Throwing error after deployment of asp.net project

I am using webforms, it works fine on local machine but the time when i deployed the project server on it throws me the following error. I am not getting where it is coming from.
i am using following packages in the project:
Captcha.3.0.16.0
jQuery.2.1.3
jQuery.UI.Combined.1.11.4
Here is the error screen which i am getting:
Error Description:
Server Error in '/CabeePortal' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Reference.svcmap: Could not load file or assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Source Error:
[No relevant source lines]
Source File: /CabeePortal/App_WebReferences/CabPortalWS/ Line: 1
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

Why does loading System.Data 4.0.99.99 succeed?

To our surprise, the following statement does not throw an exception!
Assembly.Load("System.Data, Version=4.0.99.99, Culture=neutral, PublicKeyToken=b77a5c561934e089");
The GAC contains only the version 4.0.0.0 - there is no 4.0.99.99. Note that trying to load 4.1.0.0 fails. We observed this behavior for .NET framework assemblies only.
Why is that so? Are there any default assembly binding redirects for .NET framework assemblies in place? Is there some other magic going on?
To my knowledge, strongly-named assemblies should only be loaded if the exact same version is found.
As Hans Passant mentioned in the comments, the CLR contains a retargeting mechanism for framework assemblies that redirects references to old framework libraries to newer ones. You can see that mechanism at work by looking at the Fusion Log (using fuslogvw.exe and configuring it to log all binds to disk), which contains the information "Version redirect found in framework config":
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\fabian.schmied\Desktop\Temp\ConsoleApplication3\ConsoleApplication3\bin\Debug\ConsoleApplication3.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Version redirect found in framework config: 2.0.0.0 redirected to 4.0.0.0.
LOG: Post-policy reference: System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
LOG: Found assembly by looking in the GAC.
In your sample, the Fusion log contains an equivalent line:
LOG: Version redirect found in framework config: 4.0.99.99 redirected to 4.0.0.0.
From that, I conclude that the same mechanism comes into play here. It seems that all references to System.Data up to 4.0.65534.65534 are redirected to 4.0.0.0.
(For versions starting from 4.1.0.0, the retargeting no longer kicks in.)

Web API Deployment error

I get the following error when deploying my Web API Project that is targeting the .NET 4.5 Framework. I have made sure that all the referenced DLL's are in the bin folder.
Please have a look below and see the error:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: The 'targetFramework' attribute in the element of the Web.config file is used only to target version 4.0 and later of the .NET Framework (for example, ''). The 'targetFramework' attribute currently references a version that is later than the installed version of the .NET Framework. Specify a valid target version of the .NET Framework, or install the required version of the .NET Framework.
Source Error:
Line 22: </appSettings>
Line 23: <system.web>
Line 24: <compilation debug="true" targetFramework="4.5" />
Line 25: <httpRuntime targetFramework="4.5" />
Line 26: <authentication mode="None" />
Source File: C:\inetpub\wwwroot[website folder name]\web.config Line: 24
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
If i comment out line 24 and 25 i get a different error:
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load file or assembly 'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
Source Error:
Line 109: <add assembly="System.Web.DynamicData, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 110: <add assembly="System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Line 111: <add assembly="*" />
Line 112: </assemblies>
Line 113: <buildProviders>
Source File: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config Line: 111
Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Net.Http' could not be loaded.
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
Are there two related in anyway?
How do i go about solving this problem?
Any help would be greatly appreciated.
Activate the feature WCF HTTP Activation for .NET 3.5 and 4.5 and try again:

Categories