The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

Last post 04-14-2009 12:59 PM by dunxz. 12 replies.

Sort Posts:

  • The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    08-13-2007, 8:54 PM
    • Member
      55 point Member
    • acl123
    • Member since 01-30-2007, 11:24 PM
    • Posts 64

    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.
     

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    08-20-2007, 4:40 AM
    • Member
      24 point Member
    • CYCLIST
    • Member since 08-30-2005, 8:03 AM
    • Baltimore
    • Posts 5

    I'm getting the same error, "The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception" on a previously working website hosted at GoDaddy.com.  The error does not occur for the same page on my development machine.  The error started occurring within the last few weeks (it is now August 19th).  I'm not using any third party products in the website, but I am using a UserControl in the page header.   I researched the problem on Google, and one person wrote that the IIS service needs to be restarted.

     

    Bill
  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    08-20-2007, 8:19 PM
    • Member
      55 point Member
    • acl123
    • Member since 01-30-2007, 11:24 PM
    • Posts 64

     Yep, tried an IIS reset and it didn't work.

    We had no solution but to move to a new host which solved the problem.

    This error is nasty. Beware all .Net users! 

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    11-05-2007, 1:22 PM
    • Member
      16 point Member
    • codertown
    • Member since 11-05-2007, 3:17 PM
    • Posts 17

    Guys, any update on the problem? We have the same exception with godaddy web hosting. Locally works just fine. We put  AJAX Toolkit dll in Bin folder, we do not put Extensions dll there (as it's installed already on the server and as godaddy recommends).

     

    Cannot find other solutions rather than change the web hosting, but no guarantee if another one won't have the same issue... :(

    The sad part is, looks like some ppl have AJAX working fine including AJAX Toolkit as well on godaddy windows hosting. How come?!

     

    http://www.west-wind.com/WebLog/ShowPost.aspx?id=3381  - no solution :(

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    11-05-2007, 7:09 PM
    • Member
      55 point Member
    • acl123
    • Member since 01-30-2007, 11:24 PM
    • Posts 64

    Hi,

    We ended up starting again on a completely fresh install of the VPS on a different machine. Not fun at all.

    The problem hasn't come back for a few months since then, so obviously this is not a code or site configuration issue. 

    Still, everyday I worry about it returning... it's like a ticking time bomb. 

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    11-05-2007, 10:38 PM
    • Member
      16 point Member
    • codertown
    • Member since 11-05-2007, 3:17 PM
    • Posts 17

    acl123:

    Hi,

    We ended up starting again on a completely fresh install of the VPS on a different machine. Not fun at all.

    The problem hasn't come back for a few months since then, so obviously this is not a code or site configuration issue. 

    Still, everyday I worry about it returning... it's like a ticking time bomb. 

    Thanks for the update even though it's bad news. :( In our case we just cannot reinstall anything on shared web hosting. Looks like we have bad luck with our server there and that issue happens for us. Some of their users have AJAX Toolkit working fine though.

     

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    11-06-2007, 10:59 AM
    • Member
      16 point Member
    • codertown
    • Member since 11-05-2007, 3:17 PM
    • Posts 17
    follow-up: We removed all references to AJAX whatsoever and tried to use free date picker control (BasicDatePicker) - and we've got the same error when accessing the page with that control on it. Something must be wrong with the server setup...
  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    11-06-2007, 6:16 PM
    • Member
      55 point Member
    • acl123
    • Member since 01-30-2007, 11:24 PM
    • Posts 64

    Good luck. Let us know if you find a solution.

    By the way, when we were setting up our VPS we were quite aggressive with security and removed or turned off quite a few Windows components that we didn't think were necessary. I have a suspicion this was the cause of the problem. Are you on shared hosting, or do you have access to your server?

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    11-06-2007, 6:40 PM
    • Member
      16 point Member
    • codertown
    • Member since 11-05-2007, 3:17 PM
    • Posts 17

    acl123:

    Good luck. Let us know if you find a solution.

    By the way, when we were setting up our VPS we were quite aggressive with security and removed or turned off quite a few Windows components that we didn't think were necessary. I have a suspicion this was the cause of the problem. Are you on shared hosting, or do you have access to your server?

    we are on shared hosting, no control over it; we have no time to wait till godaddy or microsoft will come up with a solution so we move to another hosting :) Hopefully it will be better (but not cheaper though).
  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    01-05-2008, 2:38 AM
    • Member
      17 point Member
    • TravisWhidden
    • Member since 07-12-2006, 3:18 AM
    • Las Vegas
    • Posts 4

    Sorry to bring this back up.

    I dont know if its related, but I never had this problem for years. It  just showed up.  I recently installed .net 3.5 and of course all the service packs for .net in one day (yesterday). 

    I wonder if its related to the .net framework service pack.  I will have to find a resolution in the code.

    Travis

    Travis Whidden
  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    01-08-2008, 8:10 PM
    • Member
      55 point Member
    • acl123
    • Member since 01-30-2007, 11:24 PM
    • Posts 64

    Given the numer of people complaining about this error, the seriousness of the problem (as it tends to totally destroy your application), and the fact that the error doesn't look like it's been fixed in 3.5, maybe we should look into contacting Microsoft about it. Now, how do I go about that...

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    11-28-2008, 5:21 AM
    • Member
      18 point Member
    • zarzar
    • Member since 09-18-2007, 8:52 AM
    • Posts 14

    Hello

    Today I get this #6`[|{ Angry exception for the first time on a test server...

    Few minutes later.. gone ! very very strange Confused

    Read this > http://blogs.msdn.com/vijaysk/archive/2008/09/02/using-themes-in-asp-net-loads-system-drawing-namespace.aspx?CommentPosted=true#commentmessage

     

  • Re: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception

    04-14-2009, 12:59 PM
    • Member
      2 point Member
    • dunxz
    • Member since 04-14-2009, 12:57 PM
    • Posts 1

    I'm also getting this error and hunting for a solution.

    the following post:

    http://blogs.msdn.com/vijaysk/archive/2008/09/02/using-themes-in-asp-net-loads-system-drawing-namespace.aspx?CommentPosted=true#commentmessage 

    refers to a hot fix: http://support.microsoft.com/kb/954316

    I'm unclear about version nos. Is this fix included in 3.5SP1? The version no. is lower but datetime stamp is higher. Does anyone have any more info?

Page 1 of 1 (13 items)