Linq2db: .net core2.2 mysql [DataConnection.DefaultSettings] throw an Exception

Created on 26 Apr 2019  路  5Comments  路  Source: linq2db/linq2db

Use .net core2.2, reference demo,
use [DataConnection.DefaultSettings = new Settings();]
throw an exception

Exception message:Could not load file or assembly 'System.Data.SqlClient, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Stack trace:
{System.TypeInitializationException: The type initializer for 'LinqToDB.Data.DataConnection' threw an exception. ---> 
System.TypeInitializationException: The type initializer for 'LinqToDB.DataProvider.SqlServer.SqlServerTools' threw an exception. ---> 
System.IO.FileLoadException: Could not load file or assembly 'System.Data.SqlClient, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 
The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Settings.cs
```c#
public class ConnectionStringSettings : IConnectionStringSettings
{
public string ConnectionString { get; set; }
public string Name { get; set; }
public string ProviderName { get; set; }
public bool IsGlobal => false;
}

public class Settings : ILinqToDBSettings
{
public IEnumerable DataProviders => Enumerable.Empty();

public string DefaultConfiguration => "MySql";
public string DefaultDataProvider => "MySql";

public IEnumerable<IConnectionStringSettings> ConnectionStrings
{
    get
    {
        yield return new ConnectionStringSettings
        {
            Name = "MySql",
            ProviderName = "MySql",
            ConnectionString = "Server=xxx;Port=3306;Database=xxx;Uid=root;Pwd=xxx;charset=utf8;"
        };
    }
}

}

Startup.cs
```c#
DataConnection.DefaultSettings = new Settings();

Environment details

linq2db version: 2.7.0
Database Server: E.g. Windows Server 2008R2
Database Provider: E.g. MySql
Operating system: E.g. Windows 10
Framework version: .NET Core 2.2

mssql has-pr

All 5 comments

Right now System.Data.SqlClient is a direct dependency of linq2db. Probably it's time to get rid of it as it also creates issue for xamarin

F..k

Install System.Data.SqlClient version 4.5.1 or latest to your project and it should work. Never mind that this is for MySql provider.
We will fix this broken dependency.

Looks like we referenced wrong version of System.Data.SqlClient in nuget. linq2db 2.7.x built using System.Data.SqlClient 2.6.0, but nuget references 4.5.1. As workaround - manually update reference to System.Data.SqlClient to 2.6.0

We will fix dependency version by #1744 in next bugfix release. For explicit dependency removal task tracking use #1715

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MaceWindu picture MaceWindu  路  4Comments

a-karpov-parc picture a-karpov-parc  路  4Comments

nviktor picture nviktor  路  6Comments

sdanyliv picture sdanyliv  路  3Comments

jges42 picture jges42  路  5Comments