【发布时间】:2011-12-11 02:18:54
【问题描述】:
我正在尝试将 64 位版本的 ELMAH 1.2 包含在 IIS Express 中本地托管的 ASP.NET 应用程序中。我引用了 Elmah.dll 的发布版本,以便将其复制到 bin 文件夹中。出于本地工作站配置的目的,我只想将异常记录到 XML 文件中。因此,我将 ELMAH 配置如下:
<configuration>
<sectionGroup name="elmah">
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
</sectionGroup>
<elmah>
<errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="C:\Logs\Elmah" />
</elmah>
<system.webServer>
<handlers>
<add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
<modules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" />
</modules>
</system.webServer>
</configuration>
当我从 Visual Studio 启动调试会话时,网站会加载并出现以下运行时错误:
无法加载文件或程序集“System.Data.SQLite”或其依赖项之一。试图加载格式不正确的程序。
堆栈跟踪如下所示:
[BadImageFormatException: Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +60
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +555
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +308
System.Reflection.Assembly.Load(String assemblyString) +51
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +115
[ConfigurationErrorsException: Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +1031
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +346
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +85
System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +54
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +274
System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies() +64
System.Web.Compilation.BuildManager.CallPreStartInitMethods() +235
System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1107
[HttpException (0x80004005): Could not load file or assembly 'System.Data.SQLite' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +763
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +156
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +243
问题是,为什么 ELMAH 会导致运行时尝试加载 System.Data.SQLite,因为我不想使用 SQLite 记录异常?另外,我该如何解决这个问题(我已经在 ELMAH 谷歌组和 StackOverflow 上到处查看了)?
【问题讨论】:
-
一种解决方法是不引用 Elmah 程序集。当我这样做时,我没有得到问题中描述的运行时异常。唯一的问题是我无法使用信号功能或捕获 global.asax 中的 ErrorLog_Logged 事件,如stackoverflow.com/questions/2143146/… 中所述。
标签: sqlite elmah assembly-loading