I am trying to include the 64-bit version of ELMAH 1.2 into an ASP.NET application that is hosted locally in IIS Express. I referenced the release version of Elmah.dll so that it would copy to the bin folder. For local workstation configuration purposes, I only want to log exceptions to XML files. As a result, I configured ELMAH as follows:
<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>
When I start a debugging session from Visual Studio, the site loads up and I get the following runtime error:
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.
The stack trace looks as follows:
[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
The question is, why would ELMAH cause the runtime to try to load System.Data.SQLite since I do not want to use SQLite for logging the exception? Also, how can I resolve this issue (I looked everywhere on the ELMAH google group and on StackOverflow already)?
It's not an issue with Elmah or SQLite, the problem is that IISExpress runs in 32 bit on your desktop. You'll need to run 32bit for your desktop, 64bit should be fine for production.
Check out this: http://learn.iis.net/page.aspx/1010/iis-75-express-readme/, especially: