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

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 15 (2 by maintainers)

Most upvoted comments

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).