Hi,
All of a sudden I started getting this nasty exception all over the place:
The type initializer for 'System.Drawing.ToolboxBitmapAttribute'
threw an exception.
Some relevant observations:
* The error started occuring a few hours after
the last deployment to the live server, not immediately after. So it
basically started occuring of its own accord.
* We have recently moved
to a new host (a VPS). The error only occurs on that server, not our local
server nor at the old host's (which was a shared environment).
* The problem is basically the same
as this guys:
http://www.west-wind.com/WebLog/posts/3381.aspx
*
I tried reinstalling Ajax extensions, then our website in IIS, then finally
the .Net 2 framework. But the error still occurs after all this.
* The error occurs on line 1, which is just the page directive:
<%@ Page
Language="C#"
AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="Test.WebForm1" %>
I'm finding it difficult to get a decent trace, but here is one that our CMS
provided:
The type initializer for
'System.Drawing.ToolboxBitmapAttribute' threw an exception.
at
System.Web.UI.TemplateParser.ProcessException(Exception ex)
at
System.Web.UI.TemplateParser.ParseStringInternal(String
text, Encoding fileEncoding)
at
System.Web.UI.TemplateParser.ParseString(String text,
VirtualPath virtualPath, Encoding fileEncoding)
at
System.Web.UI.TemplateParser.ParseFile(String
physicalPath, VirtualPath virtualPath)
at
System.Web.UI.TemplateParser.ParseInternal()
at
System.Web.UI.TemplateParser.Parse()
at
System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType()
at System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)
at
System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders()
at
System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath,
Boolean noBuild, Boolean allowCrossApp,
Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context,
VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean
allowBuildInPrecompile)
at
System.Web.UI.TemplateControl.LoadControl(VirtualPath
virtualPath)
at
System.Web.UI.TemplateControl.LoadControl(String
virtualPath)
at umbraco.macro.loadUserControl(String fileName,
Hashtable attributes, page umbPage)
My own code doesn't use the ToolboxBitmapAttribute, but third party products like Peter Blum's and Telerik's do.
Peter Blum replied with some useful hints:
* The "type initializer" concept probably needs some research, but I'm
guessing that is an important clue. A quick web search of "type initializer" finds many situations it occurs for a variety of classes.
* The stack trace suggests that this is happening as ASP.NET is compiling your
web form. The error is happening as the ASP.NET parser runs. Again this is
external from my code (even creating or "type initializing" the attribute is
not something my code does).
This problem seems to be a rare but devastating flaw which hopefully Microsoft can provide a fix for ASAP.