title: ASP.NET .ASHX image generation. NotSupportedException
body: <p>I am using the following code to draw an image on the fly in my ASP.NET web application.</p>
  
  <pre><code>Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
      Dim js As New JavaScriptSerializer
      Dim ai As absencestruct = js.Deserialize(Of absencestruct)(CStr(context.Request.QueryString.Item("json")))
  
      'Ensure font is readable (half height of block or 12px whichever is smaller)
      Dim f As Font = New Font("Calibri", Math.Min(CInt(CDbl(ai.size.height) / 2.5), 12), GraphicsUnit.Pixel)
  
      Dim img As New Bitmap(CInt(ai.size.width), CInt(ai.size.height))
      Dim g As Graphics = Graphics.FromImage(img)
  
      g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality
  
      If ai.textStyle &lt;&gt; textStyleEnum.invisible Then
          g.Clear(Color.White)
      End If
  
      Dim r As New Rectangle(1, 1, CInt(ai.size.width) - 1, CInt(ai.size.height) - 1)
  
      r = New Rectangle(r.Left + 2, r.Top + 2, r.Width - 4, r.Height - 4)
  
      drawAbsence(ai, True, r, g)
      If ai.abs2.type &lt;&gt; AbsenceItem.halfDays.Errored AndAlso ai.drawStyle = AbsenceItem.drawStyle.orphan Then
          drawAbsence(ai, False, r, g)
      End If
  
      Dim s As SizeF = g.MeasureString(ai.day.ToString, f)
      Dim br As SolidBrush = CType(Brushes.Black, SolidBrush)
      If ai.textStyle = textStyleEnum.otherMonth Then br = CType(Brushes.Gray, SolidBrush)
  
      If ai.textStyle &lt;&gt; textStyleEnum.invisible Then
          g.DrawString(ai.day.ToString, f, br, New Point(CInt((CDbl(ai.size.width) / 2) - CInt(s.Width / 2)), CInt((CDbl(ai.size.height) / 2) - CInt(s.Height / 2))))
      End If
  
      context.Response.ContentType = "image/png"
      img.Save(context.Response.OutputStream, ImageFormat.Png)
      img.Dispose()
  End Sub
  </code></pre>
  
  <p>Previously this worked absolutely fine, however all of a sudden this now errors as soon as it reaches the </p>
  
  <pre><code>img.dispose
  </code></pre>
  
  <p>I get an exception NotSupportedException "Specified Method is not supported"</p>
  
  <p>I removed the dispose call to see what happens... at which point I get the exact same error on the</p>
  
  <pre><code>End Sub
  </code></pre>
  
  <p>As I believed this to be nearly impossible I have tried both restarting PC and Visual Studio 2012. No effect.</p>
  
  <p>It should be noted that if I skip over the errors the image works perfectly fine, however as I am sure you can appreciate when the page draws anything up to 50 of these images skipping over them can be quite time consuming, on top of this if there is any chance that the image would fail as a result of this I am sure my clients would be less than impressed.</p>