Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft.SqlServer.Types: Error loading msvcr120.dll (ErrorCode: 5)

In our project we are using the following nuget package:

Microsoft.SqlServer.Types

Everything has worked fine until recently without me obviously changing anything important the ASP.NET application breaks when starting with following exception:

Error loading msvcr120.dll (ErrorCode: 5)

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.

Exception Details: System.Exception: Error loading msvcr120.dll (ErrorCode: 5)

The stacktrace:

[Exception: Error loading msvcr120.dll (ErrorCode: 5)]
SqlServerTypes.Utilities.LoadNativeAssembly(String nativeBinaryPath, String assemblyName) in E:\Dev\Jacobo\ServerApi\SqlServerTypes\Loader.cs:43
SqlServerTypes.Utilities.LoadNativeAssemblies(String rootApplicationPath) in E:\Dev\Jacobo\ServerApi\SqlServerTypes\Loader.cs:28
Jacobo.ServerApi.WebApiApplication.Application_Start() in E:\Dev\Jacobo\ServerApi\Global.asax.cs:26

[HttpException (0x80004005): Error loading msvcr120.dll (ErrorCode: 5)]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +529
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +185
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +421
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +359

[HttpException (0x80004005): Error loading msvcr120.dll (ErrorCode: 5)] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +534 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +117
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +726

The application breaks in following method:

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()));
            }
        }

Which is part of loader.cs which is a part of the SqlServerTypes nuget package.

I checked the bin folder and located the SqlServerTypes assemblies existing there. I am really unsure what has gone wrong here.

enter image description here

like image 948
Jakub Holovsky Avatar asked Oct 25 '17 07:10

Jakub Holovsky


2 Answers

I encountered this issue today. The fix I needed to implement was to ensure the SQL Server types files were part of my project so they would be produced in the publish output:

DLLs in solution explorer

Just ensure that Copy to Output Directory is set for each of the relevant DLL files. If you do not see them in your solution explorer, you may need to select to show all files and then right click them to Include in Project.

Added unreferenced files in solution explorer

like image 155
jocull Avatar answered Nov 07 '22 14:11

jocull


Based on the error code 5 I would say the identity the web app is running doesn't have access to the path that the DLL is located.

The error code 5 means: ERROR_ACCESS_DENIED.
Please check that the identity has permissions to that folder/file.

like image 3
Mihail Stancescu Avatar answered Nov 07 '22 13:11

Mihail Stancescu