Microsoft.SqlServer.Types:加载msvcr120.dll时出错(ErrorCode:5)

时间:2017-10-25 07:19:11

标签: c# asp.net .net sql-server

在我们的项目中,我们使用以下nuget包:

Microsoft.SqlServer.Types

直到最近,一切都运行良好,没有我明显改变ASP.NET应用程序在以下异常开始时中断的任何重要事项:

  

加载msvcr120.dll(ErrorCode:5)时出错

     

描述:执行期间发生了未处理的异常   当前的网络请求。请查看堆栈跟踪了解更多信息   有关错误的信息以及它在代码中的起源。

     

异常详细信息:System.Exception:加载msvcr120.dll时出错   (ErrorCode:5)

stacktrace:

  

[例外:加载msvcr120.dll时出错(ErrorCode:5)]
  SqlServerTypes.Utilities.LoadNativeAssembly(String nativeBinaryPath,   字符串assemblyName)in   E:\开发\雅各布\ ServerApi \ SqlServerTypes \ Loader.cs:43
  SqlServerTypes.Utilities.LoadNativeAssemblies(字符串   rootApplicationPath)in   E:\开发\雅各布\ ServerApi \ SqlServerTypes \ Loader.cs:28
  Jacobo.ServerApi.WebApiApplication.Application_Start()in   E:\开发\雅各布\ ServerApi \ Global.asax.cs中:26

     

[HttpException(0x80004005):加载msvcr120.dll时出错(ErrorCode:   5)]
  System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext的   上下文,HttpApplication app)+529
  System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr的   appContext,HttpContext上下文,MethodInfo []处理程序)+185
  System.Web.HttpApplication.InitSpecial(HttpApplicationState状态,   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):加载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

应用程序按以下方法中断:

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

这是 loader.cs 的一部分,它是SqlServerTypes nuget包的一部分。

我检查了bin文件夹并找到了那里存在的SqlServerTypes程序集。我真的不确定这里出了什么问题。

enter image description here

2 个答案:

答案 0 :(得分:2)

根据错误代码5,我会说Web应用程序运行的标识无法访问DLL所在的路径。

错误代码5表示:ERROR_ACCESS_DENIED 请检查该标识是否具有该文件夹/文件的权限。

答案 1 :(得分:2)

我今天遇到了这个问题。我需要实现的修复是确保SQL Server类型文件是我的项目的一部分,因此它们将在发布输出中生成:

DLLs in solution explorer

确保为每个相关的DLL文件设置Copy to Output Directory。如果您在解决方案资源管理器中没有看到它们,则可能需要选择显示所有文件,然后右键单击它们Include in Project

Added unreferenced files in solution explorer