locked
System.Drawing Error: Can or Cannot it be used in an ASP.Net application RRS feed

  • Question

  • User-526849425 posted

    We are using System.Drawing in and application to manipulate images in a web application (rotate, flip, etc).  For the last month we have been getting the following error very sporadically.

    "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    Based on the MSDN Library it appears that we should not be using System.Drawing in our web application (see insert below).

    Classes within theSystem.Drawing.Imaging namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

    This just does not seem right since there is a whole forum dedicated on this site for using System.Drawing in ASP.Net applications.  Plus, all the Image Editor controls I have found use Sytem.Drawing, so that is another reason I am thinking it is not really an issue with System.Drawing.  So the questions I have are:

    1) Has anyone else has this issue when using System.Drawing in an ASP.Net application?  If so, what was the fix.


    2)  The line that throws the error is below. Could the issue be that we are using a MemoryStream and not really an issue with System.Drawing?  Would using a different type of stream take care of the issue.

    using (System.Drawing.Image oFullImg = System.Drawing.Image.FromStream(msImage)) 


    3) If there really is a problem and we should not be using System.Drawing, what other alternatives are there for manipulating images on a web site.

    This is becoming a more critical issue as it drags on, so the quicker I can find a solution the better.  Any help will be appreciated.


    Friday, July 10, 2009 10:52 AM

Answers

  • User1052258516 posted

    Has anyone else has this issue when using System.Drawing in an ASP.Net application?  If so, what was the fix.
    I Have a site that resizes images for users and I also get memory based exceptions once in awhile, I was never able to find a fix even after pulling the actual Windows API exceptions being thrown.

    This just does not seem right since there is a whole forum dedicated on this site for using System.Drawing in ASP.Net applications.
     Just because there are people using the API like this and there is a forum does not mean it's ok to do so.  Microsofts warning is so they don't get support calls on the subject.  Back in the day MS frowned upon calling the Windows API directly from VB6 and we still did it anyway to get cool features.

    You may want to check out the System.Windows.Media.Imaging Namespace (shipped with the WPF .NET 3.0 library) and see if you can use something in there.  This library is supported under asp.net.<!---->

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 11, 2009 1:50 PM