title: Microsoft.SqlServer.Types: Error loading msvcr120.dll (ErrorCode: 5)
body: <p>In our project we are using the following nuget package:</p>
  
  <p><strong>Microsoft.SqlServer.Types</strong></p>
  
  <p>Everything has worked fine until recently without me obviously changing anything important the ASP.NET application breaks when starting with following exception:</p>
  
  <blockquote>
    <p>Error loading msvcr120.dll (ErrorCode: 5)</p>
    
    <p>Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.Exception: Error loading msvcr120.dll
    (ErrorCode: 5)</p>
  </blockquote>
  
  <p>The stacktrace:</p>
  
  <blockquote>
    <p>[Exception: Error loading msvcr120.dll (ErrorCode: 5)]<br>
    SqlServerTypes.Utilities.LoadNativeAssembly(String nativeBinaryPath,
    String assemblyName) in
    E:\Dev\Jacobo\ServerApi\SqlServerTypes\Loader.cs:43<br>
    SqlServerTypes.Utilities.LoadNativeAssemblies(String
    rootApplicationPath) in
    E:\Dev\Jacobo\ServerApi\SqlServerTypes\Loader.cs:28<br>
    Jacobo.ServerApi.WebApiApplication.Application_Start() in
    E:\Dev\Jacobo\ServerApi\Global.asax.cs:26</p>
    
    <p>[HttpException (0x80004005): Error loading msvcr120.dll (ErrorCode:
    5)]<br>
    System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext
    context, HttpApplication app) +529<br>
    System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr
    appContext, HttpContext context, MethodInfo[] handlers) +185<br>
    System.Web.HttpApplication.InitSpecial(HttpApplicationState state,
    MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172<br>
    System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr
    appContext, HttpContext context) +421<br>
    System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr
    appContext) +359</p>
    
    <p>[HttpException (0x80004005): Error loading msvcr120.dll (ErrorCode:
    5)]    System.Web.HttpRuntime.FirstRequestInit(HttpContext context)
    +534    System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +117<br>
    System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest
    wr, HttpContext context) +726</p>
  </blockquote>
  
  <p>The application breaks in following method:</p>
  
  <pre><code>private static void LoadNativeAssembly(string nativeBinaryPath, string assemblyName)
          {
              var path = Path.Combine(nativeBinaryPath, assemblyName);
              var ptr = LoadLibrary(path);
              if (ptr == IntPtr.Zero)
              {
                  throw new Exception(string.Format(
                      "Error loading {0} (ErrorCode: {1})",
                      assemblyName,
                      Marshal.GetLastWin32Error()));
              }
          }
  </code></pre>
  
  <p>Which is part of <strong>loader.cs</strong> which is a part of the SqlServerTypes nuget package.</p>
  
  <p>I checked the bin folder and located the SqlServerTypes assemblies existing there. I am really unsure what has gone wrong here.</p>
  
  <p><a href="https://i.stack.imgur.com/nnTMl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nnTMl.png" alt="enter image description here"></a></p>