System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform

.net-core .net-standard entity-framework-core

Question

I want to call a .netstandard2.0 library from a framework 4.7.2 library.

I set up some test projects to check whether this would work.

The test passes using a .Net Core 2.1 test project but fails with a framework 4.7.2 test project.

The call stack is

Test method UnitTestProject3.UnitTest1.TestMethod1 threw exception: 
System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform.
    at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
   at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func`2 operation, Func`2 verifySucceeded, TState state)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at lambda_method(Closure , QueryContext )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass17_0`1.<CompileQueryCore>b__0(QueryContext qc)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
   at SBD.VivPackAndSend.PackAndSend.GetReadyBy(Int32 headId, String connectionString) in D:\devnet10\SBD.Common\SBD.VivPackAndSend\PackAndSend.cs:line 67
   at UnitTestProject3.UnitTest1.TestMethod1()

The project file is

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Library</OutputType>
    <TargetFramework>netstandard2.0</TargetFramework>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  <ApplicationIcon />
    <StartupObject />
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>Software by Design.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" /> 
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\StandardCommon\SBD.StandardCommon.csproj" />
  </ItemGroup>

</Project>
1
1
8/25/2019 4:35:09 AM

Popular Answer

I got it working in the test project by adding a reference to System.Data.SqlClient 4.5.0.1

0
8/25/2019 4:57:30 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow