1

What could cause a TypeLoadException from an auxiliary assembly in an ASP.NET website in one environment, but not another? Here's what I have:

  • Company.Web, a .NET class library; references System.Web 4.0
  • Company.Web contains some HttpResponse extension methods
  • Company.Web contains a MediaRequestHandler (: IHttpHandler) that references my HttpResponse extensions, plus HttpContext and related classes
  • Company.UI, an ASP.NET WebForms application assembly; references System.Web 4.0 and Company.Web
  • Those references in both projects are <Reference Include="System.Web" />
  • MediaRequestHandler configured as shown below
  • Server ABC, with site 1 and site 2 in IIS
  • DEV branch, from where I built this code to Server ABC, site 1
  • MAIN branch, to where I merged this code en mass, and from where I built to Server ABC, site 2
  • These are Sitecore sites.

This works on site 1, but I am getting a TypeLoadException in site 2 when it tries to invoke my MediaRequestHandler. There aren't many details in the exception (below). I ran fuslogvw on the server with failures logged and saw nothing; I ran it with everything logged and saw a 'successful partial load' on Company.Web. The latter appears to be normal behavior; certainly the assembly is loading because everything else in it works.

The bullets above are areas where I suppose I may have messed something up, but I've checked the merge and the basic site configs, and I can't see any differences. My next step is a deep dive into configuration compares, but meanwhile, can anyone can provide suggestions on where to focus my investigation?

The config:

<system.webServer>
  <handlers>
    <add verb="*" path="sitecore_media.ashx" type="Company.Web.Media.MediaRequestHandler, Company.Web" name="Company.MediaRequestHandler" />
  ...
<system.web>
  <httpHandlers>
    <add verb="*" path="sitecore_media.ashx" type="Company.Web.Media.MediaRequestHandler, Company.Web" />

The exception:

Exception information: 
    Exception type: TypeLoadException 
    Exception message: Could not load type 'Company.Web.Media.MediaRequestHandler' from assembly 'Company.Web'.
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
   at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
   at System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type)
   at System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type)
   at System.Web.Configuration.HandlerFactoryCache..ctor(String type)
Kimberly
  • 2,657
  • 2
  • 16
  • 24
  • Check these links if they help [How can I troubleshoot : System.TypeLoadException?](http://stackoverflow.com/a/20549209/468718) and [What could be causing a System.TypeLoadException?](http://stackoverflow.com/a/16086422/468718) also try using Fusion Log viewer if that gives more verbose info into this.. – Harsh Baid Aug 06 '14 at 03:45

1 Answers1

2

A type load exception means the requested type Company.Web.Media.MediaRequestHandler can't be found in the specified assembly Company.Web. Because it is working in one environment but not another, I would recommend checking the following:

  1. The Company.Web assembly has not been updated on the problem server/site. In other words, the Company.Web.dll on the problem server/site does not represent your latest/target build containing the Company.Web.Media.MediaRequestHandler.

  2. There is an error in your configuration and it is referencing the wrong type. In other words, Company.Web.Media.MediaRequestHandler is not actually the correct type name.

  3. Spelling error. Similar to #2 above, the name of the type is misspelled in your configuration reference or in the assembly itself.

In my experience, 9 times out of 10 the culprit is #1.

Adam Weber
  • 2,395
  • 21
  • 24
  • Accepted for generally good advice - thanks. This was not exactly the case. The dll had been updated, but it was not identical to the binary on the other site. Then again, I'm not sure if it should have been, given it was built from a separate branch. We have an automated build process which had been perfectly reliable previously, and that day's build did complete successfully. The code file, project file, and config changes all merged properly, and the config got updated in the site root. I never did find the actual issue, but the next build fixed it. – Kimberly Sep 03 '14 at 07:09
  • You gave me faith! `SVGChart` vs `SGVChart` :) – it3xl Jul 24 '19 at 10:54