无法加载DLL'sni.dll'-实体框架核心 [英] Unable to load DLL 'sni.dll' - Entity Framework Core
问题描述
在Visual Studio 2017的ASP.Net Core应用程序中使用Entity Framework Core时,间歇性地收到错误无法加载'sni.dll'.
奇怪的是,尽管我找到了一个临时修复程序:重新启动PC.
我不知道为什么错误不断发生,我也不知道变量可能是什么.有人可以阐明可能的原因吗?我会提供完整的堆栈跟踪,但是自从决定在此处发布以来就没有发生过,当下次发生时,我将确保对其进行更新.我可以肯定地知道(因为调试捕获了异常),当EF导致从db获取数据并将其转换为实体时,就会发生这种情况.
提前感谢您的任何建议.
-编辑 这仍在发生.设法记住要捕获堆栈跟踪:
发生System.DllNotFoundException HResult = 0x80131524 消息=无法加载DLL'sni.dll':指定的网络名称不再可用. (来自HRESULT的异常:0x80070040) 来源= 堆栈跟踪: 在System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr令牌,Boolean&isRestricted)中 在System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr令牌)处 在System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent() 在System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory) 在System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject,DbConnectionPoolGroup connectionPoolGroup) 在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1重试,DbConnectionOptions userOptions) 在System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open() at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer) at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](Func
2操作,Func2 verifySucceeded, TState state) at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3
1.MoveNext() 在Microsoft.EntityFrameworkCore.Query.QueryMethodProvider中.< _Include> d__301.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1源) 在Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<> c__DisplayClass20_01.<CompileQueryCore>b__0(QueryContext qc) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1源)
添加nuget包System.Data.SqlClient v4.4.0为我解决了同样的问题.该问题并非特定于实体框架.这是由旧版本的SqlClient对API的依赖关系所引起的,该API在dotnet Core 2中不可用.
When using Entity Framework Core in an ASP.Net Core application on Visual Studio 2017 I intermittently get the error "Unable to load 'sni.dll'.
Strangely though I have found a temporary fix: restarting my PC.
I don't know why the error keeps happening, I don't know what the variable could be. Could anyone shed light on the possible cause? I would offer a full stack trace but it hasn't happened since deciding to post on here, when it next happens I'll be sure to update this. I know for certain though (as the debug catches the exception) that it happens when EF has cause to get data from the db and transform to entities.
Thanks in advance for any suggestions.
--EDIT This is still happening. Managed to remember to capture the stack trace:
System.DllNotFoundException occurred HResult=0x80131524 Message=Unable to load DLL 'sni.dll': The specified network name is no longer available. (Exception from HRESULT: 0x80070040) Source= StackTrace: at System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted) at System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token) at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent() at System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory) at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup) at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) at System.Data.SqlClient.SqlConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open() at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer) at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](Func
2 operation, Func2 verifySucceeded, TState state) at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3
1.MoveNext() at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__301.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1 source) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass20_01.<CompileQueryCore>b__0(QueryContext qc) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable
1 source)
Adding nuget package System.Data.SqlClient v4.4.0 solved the same problem for me. The problem is not specific to Entity Framework. It is caused by older version of SqlClient dependency on APIs not available in dotnet Core 2.
这篇关于无法加载DLL'sni.dll'-实体框架核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!