本文介绍了无法加载 DLL 'sni.dll' - Entity Framework Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在 Visual Studio 2017 上的 ASP.Net Core 应用程序中使用 Entity Framework Core 时,我间歇性地收到错误无法加载‘sni.dll’.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.我不知道为什么错误不断发生,我不知道变量可能是什么.任何人都可以阐明可能的原因吗?我会提供一个完整的堆栈跟踪,但自从决定在这里发帖后就没有发生过,下次发生时我一定会更新这个.我肯定知道(因为调试捕获异常)当 EF 有原因从数据库获取数据并转换为实体时会发生这种情况.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.--编辑这仍在发生.设法记住捕获堆栈跟踪:--EDITThis is still happening. Managed to remember to capture the stack trace:System.DllNotFoundException 发生HResult=0x80131524消息=无法加载 DLL 'sni.dll':指定的网络名称不再可用.(来自 HRESULT 的异常:0x80070040)来源=堆栈跟踪:在 System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, 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, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)在 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection externalConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)在 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)在 System.Data.SqlClient.SqlConnection.Open()在 Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()在 Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(布尔缓冲区)在 Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](Func2 operation, Func2 verifySucceeded, TState state)在 Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__31.MoveNext()在 Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__301.MoveNext()在 System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 源)在 Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.c__DisplayClass20_01.b__0(QueryContext qc)在 System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 源) 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, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 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](Func2 operation, Func2 verifySucceeded, TState state) at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__31.MoveNext() at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__301.MoveNext() at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass20_01.<CompileQueryCore>b__0(QueryContext qc) at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable1 source)推荐答案添加 nuget 包 System.Data.SqlClient v4.4.0 为我解决了同样的问题.该问题并非特定于实体框架.这是由于旧版本的 SqlClient 依赖于 dotnet Core 2 中不可用的 API.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' - Entity Framework Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-15 14:24