System.PlatformNotSupportedException:在此平台上不支持System.Data.SqlClient [英] System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform

查看:364
本文介绍了System.PlatformNotSupportedException:在此平台上不支持System.Data.SqlClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从框架4.7.2库中调用.netstandard2.0库。



我建立了一些测试项目以检查其是否可行。 / p>

该测试通过.Net Core 2.1测试项目通过,但由于框架4.7.2测试项目失败。



调用堆栈为

 测试方法UnitTestProject3.UnitTest1.TestMethod1引发了异常:
System.PlatformNotSupportedException:System.Data在此平台上不支持.SqlClient。 System.Data.SqlClient.SqlConnection..ctor(String connectionString)的
Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection.CreateDbConnection()的
Microsoft.EntityFrameworkCore.Internal.LazyRef的
1.get_Value()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(布尔错误预期)
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(Boolean buffer)
在Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions。<> c__DisplayClass12_0`2。 TState状态,Func`3操作,Func`3验证成功)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute [TState,TResult](IExecutionStrategy策略,Func`2操作,Func`2验证成功,TState状态)
在Microsoft.EntityFrameworkCore.Qu ery.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](表达式查询)
在Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute [TResult](表达式)
在System.Linq.Queryable.SingleOrDefault [TSource](IQueryable`1 source,Expression`1 predicate)
在SBD.VivPackAndSend.PackAndSend.GetReadyBy(Int32 headId,字符串connectionString)在D:\devnet10\SBD.Common\SBD.VivPackAndSend\PackAndSend.cs:线67
在UnitTestProject3.UnitTest1 .TestMethod1()

项目文件为

 < Project Sdk = Microsoft.NET.Sdk> 

< PropertyGroup>
< OutputType> Library< / OutputType>
< TargetFramework> netstandard2.0< / TargetFramework>
< CopyLocalLockFileAssemblies> true< / CopyLocalLockFileAssemblies>
< ApplicationIcon />
< StartupObject />
< SignAssembly> true< / SignAssembly>
< AssemblyOriginatorKeyFile>软件,由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>


解决方案

我在测试项目中添加了一个对System.Data.SqlClient 4.5.0.1的引用


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>

解决方案

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

这篇关于System.PlatformNotSupportedException:在此平台上不支持System.Data.SqlClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆