title: Unable to load DLL 'sni.dll' - Entity Framework Core
body: <p>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'.</p>
  
  <p>Strangely though I have found a temporary fix: restarting my PC.</p>
  
  <p>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.</p>
  
  <p>Thanks in advance for any suggestions.</p>
  
  <p>--EDIT
  This is still happening. Managed to remember to capture the stack trace:</p>
  
  <blockquote>
    <p>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&amp; 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<code>1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal&amp; connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource</code>1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource<code>1 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</code>2 operation, Func<code>2 verifySucceeded, TState state)
       at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.&lt;_ShapedQuery&gt;d__3</code>1.MoveNext()
       at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.&lt;_Include>d__30<code>1.MoveNext()
       at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable</code>1 source)
       at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.&lt;>c__DisplayClass20_0<code>1.&lt;CompileQueryCore&gt;b__0(QueryContext qc)
       at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable</code>1 source)</p>
  </blockquote>