System.PlatformNotSupportedException:此平台不支持 System.Data.SqlClient [英] System.PlatformNotSupportedException: System.Data.SqlClient is not supported on this platform
本文介绍了System.PlatformNotSupportedException:此平台不支持 System.Data.SqlClient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从框架 4.7.2 库中调用 .netstandard2.0 库.
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.
使用 .Net Core 2.1 测试项目通过测试,但使用框架 4.7.2 测试项目失败.
The test passes using a .Net Core 2.1 test project but fails with a framework 4.7.2 test project.
调用栈是
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:devnet10SBD.CommonSBD.VivPackAndSendPackAndSend.cs:line 67
at 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>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="..StandardCommonSBD.StandardCommon.csproj" />
</ItemGroup>
</Project>
推荐答案
我通过添加对 System.Data.SqlClient 4.5.0.1 的引用使其在测试项目中工作
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屋!
查看全文