Azure-webjobs-sdk: Couldn't load assembly System.Data.SqlClient: System.AppDomain conflict in assemblies

Created on 19 Dec 2017  路  15Comments  路  Source: Azure/azure-webjobs-sdk

I'm trying to use System.Data.SqlClient to work with Azure SQL, but I get exception during local testing.

Repro steps

  1. Clone repository: https://github.com/PoisonousJohn/CSharpHttpCore
  2. Launch project in VS or VSCode
  3. Execute function: http://localhost:7071/api/HttpTriggerCSharp

Expected behavior

Function fires without errors

Actual behavior

I get exception during function execution:

Exception during runtime resolution of assembly 'System.Data.SqlClient, Version=4.2.0.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a': 
'System.InvalidCastException: [A]System.AppDomain cannot be cast to [B]System.AppDomain. 
Type A originates from 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.3\System.Private.CoreLib.dll'. 
Type B originates from 'System.Runtime.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.3\System.Runtime.Extensions.dll'.

Known workarounds

No any workaround for me

Related information

Provide any related information

needs-investigation

Most helpful comment

I just started a new project and ran into the same error as @justin-lovell, forcing x64 didn't make any difference. I had to downgrade the System.Data.SqlClient nuget package to version 4.4.0 (4.4.1 & 4.4.2 have this problem).

All 15 comments

I am also having this issue.

I got this error while using a net standard 2.0 lib inside a project. I finally discovered a bad format error. Made sure the project platform matched in my case x64.

@eschneider999 I don't think it's a configuration issue. If you start with a blank project and try to connect to SQL, you will get this error. Pretty serious in my opinion.

@fabiocav - you probably need to look at this. This is also probably the wrong repo.

I am also encountering this issue.

This issue is more of loading the wrong assembly version.

Packages reference <PackageReference Include="System.Data.SqlClient" Version="4.4.2" />

During runtime, the application is loading System.Data.SqlClient, Version=4.2.0.1

If there could be any further insight, I also noticed the binding to Newtonsoft being version specific too.

I just started a new project and ran into the same error as @justin-lovell, forcing x64 didn't make any difference. I had to downgrade the System.Data.SqlClient nuget package to version 4.4.0 (4.4.1 & 4.4.2 have this problem).

@TheDruidsKeeper downgrading to 4.4.0 worked for me as well. Thanks!

Downgrading System.Data.SqlClient to 4.4.0 resolved the issue for me as well.

I also had the same problem, and the downgrade made it go away for me too.

Version 4.6.0 raises similar exception:
System.Private.CoreLib: Exception while executing function: FunctionApp. System.Data.SqlClient: System.Data.SqlClient is not supported on this platform.

Thanks to @TheDruidsKeeper, downgrading to 4.4.0 solved the problem.

Downgraded to 4.50 solved it for me

Same issue here with 4.6.0, downgrade to 4.5.1 solved the problem.

@BrodaUa @HeinBehrensRR @mike1880 ; the original issue here is quite old and doesn't apply to the current production versions of the runtime. Would you mind opening a new issue with the details requested in the template and error details so we can investigate?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lopezbertoni picture lopezbertoni  路  4Comments

xt0rted picture xt0rted  路  5Comments

kamranayub picture kamranayub  路  4Comments

christopheranderson picture christopheranderson  路  3Comments

mslugx picture mslugx  路  3Comments