02 September 2008

Using Themes in ASP.NET loads System.Drawing namespace

Using the System.Drawing namespace is strongly discouraged in ASP.NET as it leads to a lot of performance/runtime problems.

Recently one of our customers reported an issue where we were getting GDI+ errors in a  normal ASP.NET application.

Exception type: System.Runtime.InteropServices.ExternalException
Message: GDI+ is not properly initialized (internal GDI+ error).
InnerException: <none>
StackTrace (generated):
    SP       IP       Function
    048CE1A0 7AE65963 System.Drawing.Bitmap..ctor(System.IO.Stream)
    048CE1C8 7AE31EAE System.Drawing.ToolboxBitmapAttribute..cctor()

StackTraceString: <none>
HResult: 80004005

The GDI+ calls were not something intentional, none of the application code contained any  reference to the System.Drawing namespace. But the namespace was getting loaded in the process as a result of applying a Theme to the page.

System.Reflection.CustomAttribute._CreateCaObject(Void*, Void*, Byte**, Byte*, Int32*)
System.Reflection.CustomAttribute.CreateCaObject(System.Reflection.Module, System.RuntimeMethodHandle, IntPtr ByRef, IntPtr, Int32 ByRef)
System.Reflection.CustomAttribute.GetCustomAttributes(System.Reflection.Module, Int32, Int32, System.RuntimeType, Boolean, System.Collections.IList)
System.Reflection.CustomAttribute.GetCustomAttributes(System.RuntimeType, System.RuntimeType, Boolean)
System.RuntimeType.GetCustomAttributes(System.Type, Boolean)
System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(System.Type)
System.ComponentModel.ReflectTypeDescriptionProvider+ReflectedTypeData.GetAttributes()
System.ComponentModel.TypeDescriptor+TypeDescriptionNode+DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
System.ComponentModel.TypeDescriptor.GetAttributes(System.Type)
System.Web.UI.ThemeableAttribute.IsTypeThemeable(System.Type)
System.Web.UI.Control.ApplySkin(System.Web.UI.Page)
System.Web.UI.Control.InitRecursive(System.Web.UI.Control)
System.Web.UI.Control.InitRecursive(System.Web.UI.Control)
System.Web.UI.Control.InitRecursive(System.Web.UI.Control)
System.Web.UI.Control.InitRecursive(System.Web.UI.Control)
System.Web.UI.Page.ProcessRequestMain(Boolean, Boolean)

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.

Bookmark and Share
Filed under: , , ,
 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# funny wallpaper &raquo; Using Themes in ASP.NET loads System.Drawing namespace said:

PingBack from http://housesfunnywallpaper.cn/?p=3514

01 September 08 at 7:36 PM
# Mike737 said:

Has a fix been released yet for this issue?

27 November 08 at 10:16 PM
# César said:

Today I get the 'System.Drawing.ToolboxBitmapAttribute' exception for the first time on a test server :(

Any news about this fix ? ;)

28 November 08 at 5:11 AM
# vijaysk said:

Please contact MS Support for assistance on this issue.

30 November 08 at 6:04 PM
# Mike737 said:

Do you have a hot fix or patch number for the issue?

MS support cannot help me unless I have a number.

I also logged the issue on connect a while back so it may be useful to respond in their as well since others seem to be experiencing the issue.

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=384571

16 January 09 at 12:21 AM
# Michael G said:

You can find the update here to fix the GDI error.

<http://support.microsoft.com/kb/954316>

Google instructions to download the hotfix.  :google: download microsoft KB hotfix if it isn't provided on the page.

22 January 09 at 9:49 AM
# Dunxz said:

Is this hotfix included in .net3.5 sp1?

14 April 09 at 5:12 PM
# Xin Gu said:

Where can I download this update? It seems that there is no download link on the page "http://support.microsoft.com/kb/954316".

Thanks.

15 April 09 at 3:01 AM
Thanks for sharing your feedback! If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish - or longer if the blogger is moderating comments.

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Page view tracker