elmah / Elmah

Error Logging Modules & Handlers for ASP.NET
https://elmah.github.io/
Apache License 2.0
310 stars 65 forks source link

The given assembly name or codebase was invalid (HRESULT: 0x80131074) #434

Closed cvocvo closed 6 years ago

cvocvo commented 6 years ago

Hi there,

I'm running Elmah with packages from Nuget in an ASP.NET MVC app targeting .NET 4.6.2

When I navigate to ~/elmah.axd I encounter a YSOD (yellow screen of death) instead of the usual elmah page loading:

Server Error in '/' Application.
The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
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.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

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.

Stack Trace: 

[FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)]
   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) +70
   System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +40
   System.Type.GetType(String typeName, Boolean throwOnError) +34
   Elmah.SimpleServiceProviderFactory.CreateFromConfigSection(String sectionName) +162
   Elmah.ErrorLog.GetDefaultImpl(HttpContext context) +134
   Elmah.ServiceContainer.GetService(Type serviceType) +49
   Elmah.ServiceCenter.FindService(Object context, Type serviceType) +25
   Elmah.ServiceCenter.GetService(Object context, Type serviceType) +31
   Elmah.ErrorLog.GetDefault(HttpContext context) +22
   Elmah.ErrorPageBase.get_ErrorLog() +32
   Elmah.ErrorLogPage.OnLoad(EventArgs e) +308
   System.Web.UI.Control.LoadRecursive() +130
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2839

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

It's working in our master branch of our project, but my branch (where I've been updating Nuget packages) is running into issues. I've confirmed:

Any ideas how I can solve this?

Best, Chris

atifaziz commented 6 years ago

Assembly Binding Log Viewer is a good tool to use for troubleshooting assembly load and binding issues. If you can run under a debugger and inspect the FileLoadException.FileName property of the exception that it can provide pointers to the offending library. Usually, these kinds of problems are also caused by bit-ness mismatch the library being loaded and the hosting process. In the past, I've seen people get into this sort of trouble by using the wrong 32-bit versus 64-bit version of the SQLite library.

cvocvo commented 6 years ago

Thank you for responding so quickly!! Interesting; I'll take a look at the log viewer. We're running a full SQL server with our projects set to compile as Any CPU with dev on x64 Windows 10 and hosting on x64 Server 2016. I think the issue is that I'm trying to add Stackify (nuget packages: StackifyLib and StackifyLib.Elmah). When I revert to a clean branch of Master and only install those I run into these errors.

Here's what I've got in my web.config (might be something misconfigured?) Inside of <configSections> image

Inside of <httpModules> image

Inside of <modules runAllManagedModulesForAllRequests=”true”> image

Inside of <configuration> image

Does that all look okay?

atifaziz commented 6 years ago

I don't know anything about StackifyLib and StackifyLib.Elmah so can't comment about that. The assembly name in the type attribute of the <errorLog> element seems suspicious and malformed so I'd start there. It would coincide with the error message that the given assembly name or codebase was invalid.

cvocvo commented 6 years ago

Confirmed it's definitely that line; I commented out the malformed line and replaced it with what we had and Elmah loads fine. I'll follow up with their team to figure out what it should be.

  <elmah>
    <!--<errorLog type="Elmah.SqlErrorLog, Elmah, StackifyLib.ELMAH.StackifyErrorLog, StackifyLib.ELMAH" connectionStringName="ErrorLoggingDbDSN" />-->
        <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ErrorLoggingDbDSN" />
    <security allowRemoteAccess="true" />
  </elmah>

Thank you for all the help! If I do get a solution, I'll post it back here for future reference if anyone stumbles across this.

cvocvo commented 6 years ago

In case anyone runs across this; we enabled Elmah to work with Stackify (and retain access to ~/Elmah.axd) with the following: In our App_Start we’ve got a Global.cs class and we’re using this:

        /// <summary>
        /// This is an application hook that elmah calls when it logs an error.
        /// We tie into this hook to also send the error our stackify retrace program
        /// </summary>
        /// <param name="sender">not used</param>
        /// <param name="args">An elmah event that contains the exception that was thrown</param>
        protected void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args)
        {
            StackifyLib.Logger.QueueException(args.Entry.Error.Exception);
        }

In web.config:

  <elmah>
    <errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="ErrorLoggingDbDSN" />
    <security allowRemoteAccess="true" />
  </elmah>

And any custom exceptions we were handling from other libraries, etc. we updated our elmah calls from: Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex)); to this: Elmah.ErrorSignal.FromCurrentContext().Raise(ex);

This probably isn't necessary but is the nicer way to do it as of Elmah 1.2

atifaziz commented 6 years ago

@cvocvo Thanks for dropping in with notes on what worked for you. I'm sure it'll help out someone someday.