Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

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


:P
On this page:

Whoa, here’s a whacky ASP.NET error that showed on the WebLog Error log sometime this evening:

 

/WebLog/posts/5039.aspx

 

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

 on 9/30/2006 4:57:08 am

 

--- Stack Trace ---

   at System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)

   at System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)

   at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)

   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)

   at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)

   at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(Type type)

   at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetAttributes()

   at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()

   at System.ComponentModel.TypeDescriptor.GetAttributes(Type componentType)

   at System.Web.UI.ThemeableAttribute.IsTypeThemeable(Type type)

   at System.Web.UI.Control.ApplySkin(Page page)

   at System.Web.UI.Control.InitRecursive(Control namingContainer)

   at System.Web.UI.Control.InitRecursive(Control namingContainer)

   at System.Web.UI.Control.InitRecursive(Control namingContainer)

   at System.Web.UI.Control.InitRecursive(Control namingContainer)

   at System.Web.UI.Control.InitRecursive(Control namingContainer)

   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 

--- Request Information ---

  Full Url: http://www.west-wind.com/WebLog/posts/5039.aspx

        IP: 66.249.65.2

   Browser: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

     Login: Anonymous

    Locale:

 

Somehow at some point in the application’s life cycle this evening this error started showing up in the running instance of the WebLog. I sure am glad I had my error email notifications off, because it generated something like 2,500 error entries in a matter of a few hours. This affected most parts of the WebLog application but not all which is also odd. The home page was fine, but the summary pages and post page were not and the home page basically uses functionality of both of those.

 

I’ve never seen this error before in any app – or this one for this matter. I recompiled the app locally and redeployed the assemblies just in case and all is fine now…

 

It seems really odd though that this failure would start showing up all of a sudden. I also log application re-starts and the last application start prior to that was about 5 hours before the first failures started showing up – probably when I made the last update on the server.

 

Anybody ever see this? I wonder if it has something to do with resource use on the server but there’s just no hint in the exception error message.

Posted in ASP.NET  Bugs  

The Voices of Reason


 

Doug Dodge
October 01, 2006

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

Any Windows auto-updates that might have caused this?

Karthik
November 23, 2006

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

Just my two cents on this one: System.Drawing is not supported on a service like ASP.NET:

See the Caution statement in the documentation below…
http://msdn2.microsoft.com/en-us/library/system.drawing.aspx

Jack Stow
March 16, 2007

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

I've been getting this error from a freshly uploaded ASP.NET 2.0 & AJAX Extensions site. Very strange as the error seems to come from a part of the framework for Windows forms, not ASP.NET. A blank .aspx file runs but that's all.

Ramesh
July 04, 2007

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

I too experience similar error in .NET/C# application...once I restarted the application's service then this error does not occur for the next 4 or 5 hours and then I started getting this "Type Initializer...threw exception" error. Guys, did any of you resolved this issue? If so, can you let me know how you did fix it? Thanks in advance!

Fraser
July 06, 2007

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

I get this exact error on my ASP.NET application - only on AJAX-enabled pages tho...

Bill Dean
August 20, 2007

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

I'm getting this error on a previously working website using ASP.NET 2.0. The error doesn't occur on my development computer. What's strange is that the error only occurs on certain pages. I can only surmise that it has something to do with pathing to the header graphic which is in a User Control. I have tried turning off "Enable Parent Paths" in the configuration to see if I can duplicate the problem on my development machine, but no luck.

Rick Strahl
August 20, 2007

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

I still see this error popping up occasionally as well. But it comes and goes which seems to indicate that it's somehow resource related (maybe when memory gets really low and the heap runs out?). It's rare that this starts popping but when it does it'll keep happening until the app is cycled.

Sergio
November 05, 2007

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

Hi all, any updates on the problem?! We have the same exception for AJAX enabled pages (with AJAX Toolkit controls) on godaddy web hosting. No problems on localhost with that.
Any idea? Godaddy support no help... :(

Ezequiel
November 12, 2007

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

Hi,

I'm facing the same problem on a VPS at vpsland.com.

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

However, other exceptions also start to appear. All messages ares related with
The type initializer for <> threw an exception.
VPS support didn't solve till now. I think that it is related to running windows as a VPS.

David Aspinall
September 16, 2008

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

Rick

Did you ever get any further with this. I am currently wrestling with it and making little progress. I have also posted the following to the asp.net site:

There have been a number of posts on these forums and others about the runtime error: "The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception." in Ajax-enabled web apps. See http://forums.asp.net/t/1146003.aspx and www.west-wind.com/Weblog/posts/3381.aspx. None offer any solace beyond file clearance, IIS reset, system re-installation, server replacement etc.

I have the misfortune of being mired in the same problem and have yet to find an exit route, having tried all the above. Has anyone discovered more information that might shed light on the problem? Has Microsoft responded to any calls for assistance?

It hit me after many months of stable and relatively trouble-free development and testing of a Ajax-enabled Web application that makes wide use of custom controls (in separate dll) and client-side scripting with AjaxControlToolkit. The complexity of the system makes exact reproduction impossible. However, here are a number of salient facts:

1. App developed in C# using Visual Studio 2005 running on stand-alone development machine with ASP.NET 2.0 and IIS 6.0;

2. Error and Stack trace at various level of InnerException:

{"Unable to load DLL 'gdiplus.dll': Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"} System.Exception {System.DllNotFoundException}
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip.Initialize()
at System.Drawing.SafeNativeMethods.Gdip..cctor()

{"The type initializer for 'Gdip' threw an exception."} System.Exception {System.TypeInitializationException}
at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromStream(IStream stream, IntPtr& bitmap)
at System.Drawing.Bitmap..ctor(Stream stream)
at System.Drawing.ToolboxBitmapAttribute..cctor()

{"The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception."} System.TypeInitializationException
at System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(Type type)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetAttributes()
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
at System.ComponentModel.TypeDescriptor.GetAttributes(Type componentType)
at System.Web.UI.ViewStateModeByIdAttribute.IsEnabled(Type type)
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Control.SaveViewStateRecursive()
at System.Web.UI.Page.SaveAllState()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

This clear points to the immediate cause. But specific nature of its occurrence points to

3. Exception only occurs when a non-empty custom control of type System.Web.UI.UserControl is loaded.

4. Exception occurs only after Response.Redirect call to page. If page loaded directly (i.e. page 'Set As Start Page') then the exception is not thrown.

5. Except in this instance all graphics, bitmaps etc are handled fine, indicating no real problem with gdiplus.dll.

Can anyone offer any information? Are upgrades likely to solve?

Michael Lyons
November 27, 2008

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

Vijayshinva Karnure from Microsoft India recently posted in his blog about the issue.

Seems like it's now a known issue for ASP.Net and a fix will be released at some point.

"When an ASPX page has to load a Theme we loop through all Controls/Types on the page and check if we can apply the theme to it(IsTypeThemeable). This involves generating  a list of attributes for the Control/Type. Its a simple call to TypeDescriptor.GetAttributes method which results in each attribute being instantiated. And this is where the trouble starts.

Controls have a ToolboxBitmap attribute which is a picture representation of the control. Its a bitmap and this results in the unintentional loading of the System.Drawing namespace in the worker process.

Currently a fix is being worked on and should be released soon."

http://blogs.msdn.com/vijaysk/archive/2008/09/02/using-themes-in-asp-net-loads-system-drawing-namespace.aspx

Duncan Smart
November 16, 2010

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


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024