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

eqfvzcg8  于 2023-05-16  发布在  其他
关注(0)|答案(3)|浏览(239)

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.

62lalag4

62lalag41#

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:

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 .

0dxa2lsx

0dxa2lsx2#

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.

c9qzyr3d

c9qzyr3d3#

In my case, I solved it by giving the IIS_IUSRS user group permissions to the project directory.

This can be done by going into the folder's properties, then under the security tab, click Edit then Add, type IIS_IUSRS and click OK

相关问题