efcore icon indicating copy to clipboard operation
efcore copied to clipboard

System.Data.SqlClient 'not supported on this platform' on Framework 4.7.2

Open Faeldor opened this issue 7 years ago • 3 comments

Quick breakdown:

  • The main application is a Windows application running .NET Framework 4.7.2 (we'll call this app1)
  • app1 calls dll of another project where the data access is built. Data access project is built in .netstandard 2.0 using EF Core (originally version 2.1.3)
  • The data access project is used in other .NET Core applications without any issues.

App1 was originally in .NET Framework 4.5 and we updated it to 4.7.2 specifically in order to use the .netstandard 2.0 data access libraries. When we hook everything up, all is well right up until the System.Data.SqlClient dll is called to build the DbConnection. We get the error:

System.Data.SqlClient is Not supported on this platform

with the following stack trace:

   at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef1.get_Value()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_02.<Execute>b__0(DbContext c, TState s)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func3 operation, Func3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func2 operation, Func2 verifySucceeded, TState state)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable1.Enumerator.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__172.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List1..ctor(IEnumerable1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)

We have attempted to resolve this issue by the following:

  • Update EF Core to 2.2.0
  • Downgrade EF Core to 2.0.0
  • Downgrade .NET Framework application to 4.7.0

All failed. Any help on this, or insight as to why EF Core doesn't want to cooperate with .NET Framework 4.7.2 would be greatly appreciated.

Faeldor avatar Feb 28 '19 18:02 Faeldor

@Faeldor Can you show your .csproj files so we can see how the references/packages are being pulled in?

ajcvickers avatar Feb 28 '19 21:02 ajcvickers

The windows application references the data access dll like:

<Reference Include="MM.Core.Business, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\lib\netstandard2.0\MM.Core.Business.dll</HintPath>
</Reference>

that application references another called MM.Core.DAL with:

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AssemblyName>MM.Core.Business</AssemblyName>
    <RootNamespace>MM.Core.Business</RootNamespace>
  </PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>..\..\Build\MMCore\</OutputPath>
</PropertyGroup>

<ItemGroup>
    <ProjectReference Include="..\DAL\DAL.csproj" />
</ItemGroup>

that application references EFCore:

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RootNamespace>MM.Core.DAL</RootNamespace>
    <AssemblyName>MM.Core.DAL</AssemblyName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <OutputPath>..\..\Build\MMCore\</OutputPath> 
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.3" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.3">      
    </PackageReference>
</ItemGroup>

Faeldor avatar Feb 28 '19 21:02 Faeldor

@Faeldor Due to the way NuGet and MSBuild work, you'll need to reference either NuGet packages or projects all the way to the application that targets a "real" target framework--i.e. not just netstandard. This is essentially because resolution of which code to actually use doesn't always happen until building for a real framework.

This is really outside the scope of EF itself. If you want to follow up further I suggest following up at https://github.com/NuGet/Home

ajcvickers avatar Mar 01 '19 22:03 ajcvickers