无法加载文件或程序集“Elmah”或其依赖项之一。该系统找不到指定的文件

Posted

技术标签:

【中文标题】无法加载文件或程序集“Elmah”或其依赖项之一。该系统找不到指定的文件【英文标题】:Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified 【发布时间】:2020-01-21 23:51:15 【问题描述】:

将 Asp.NET Core 模块安装到我的 Windows Server (2012 R2) 机器后,我收到此错误,即使我的项目中没有使用 Elmah 模块。我正在通过 Visual Studio 2017 通过 IIS (v8.5) 发布我的 Asp.NET Core 2.2 WebAPI。收到错误后,我安装了elmah.corelibrary v1.2.2(也尝试使用 Elmah.Contrib.WebApi,Elmah.MVC)并再次发布,但没有帮助。

无法通过查看堆栈跟踪来确定异常的来源。无论如何,我附上了整个异常细节:


Server Error in '/harmony-webapi' Application.

Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.
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.IO.FileNotFoundException: Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Elmah' could not be loaded.


    WRN: Assembly binding logging is turned OFF.
    To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
    Note: There is some performance penalty associated with assembly bind failure logging.
    To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stack Trace: 


[FileNotFoundException: Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.]
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +95
   System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +64
   System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +59
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +49

[ConfigurationErrorsException: Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.]
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, XmlNode node, Boolean checkAptcaBit, Boolean ignoreCase) +550
   System.Web.Configuration.ConfigUtil.GetType(String typeName, String propertyName, ConfigurationElement configElement, Boolean checkAptcaBit) +30
   System.Web.Configuration.Common.ModulesEntry.SecureGetType(String typeName, String propertyName, ConfigurationElement configElement) +57
   System.Web.Configuration.Common.ModulesEntry..ctor(String name, String typeName, String propertyName, ConfigurationElement configElement) +57
   System.Web.HttpApplication.BuildIntegratedModuleCollection(List`1 moduleList) +173
   System.Web.HttpApplication.GetModuleCollection(IntPtr appContext) +1069
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +130
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +165
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +267
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +341

[HttpException (0x80004005): Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +523
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +107
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +688

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0

【问题讨论】:

您是否在 Program.cs 或 Startup.cs 的任何地方看到“Elmah”?你的项目中是否有 Elmah 的参考或 NuGet 包? @GabrielLuci 不,Elmah 什么都没有。我在收到异常后安装了 NuGet 包。我已经在帖子中提到了这些事实。 【参考方案1】:

ELMAH 不适用于 ASP.NET Core。您可能正在寻找自托管日志或 ElmahCore 或云日志记录 elmah.io。

【讨论】:

【参考方案2】:

好的,解决了。问题是当我尝试在“默认网站”或 IIS 上的任何其他根网站下发布我的 WebAPI 时,它会引发 Elmah 异常,因为之前在现有根网站中配置了 Elmah 模块。我尝试通过在 IIS 上创建一个新网站来单独发布我的应用程序,但异常消失了。

【讨论】:

有同样的问题。我不明白“之前在现有根网站中配置了 Elmah”。不知道它是如何配置的以及为什么这很重要。

以上是关于无法加载文件或程序集“Elmah”或其依赖项之一。该系统找不到指定的文件的主要内容,如果未能解决你的问题,请参考以下文章

无法加载文件或程序集 此处的程序集名称 或其依赖项之一。访问被拒绝

无法加载文件或程序集“CefSharp.dll”或其依赖项之一

无法加载文件或程序集“***.dll”或其依赖项之一

BadImageFormatException 无法加载文件或程序集或其依赖项之一。试图加载格式不正确的程序

无法加载文件或程序集“Oracle.ManagedDataAccessDTC.DLL”或其依赖项之一

无法加载文件或程序集“msshrtmi”或其依赖项之一(Azure 表存储访问)