Re: Graphics.GetHdc causes InvalidOperationException

From: Richard Morris (khiron_at_community.nospam)
Date: 06/28/05


Date: Tue, 28 Jun 2005 03:36:11 -0700

Hi Nicole,

Thanks for answering. The problem is that assigning Full Trust to
assemblies with MS strongkey is not enough. Is it possible that some
assemblies which come from MS aren't signed with their key?

Here is the code of my test control:

public class Class1 : Control {
        public Class1() {
                SetStyle(ControlStyles.AllPaintingInWmPaint |
                        ControlStyles.DoubleBuffer |
                        ControlStyles.ResizeRedraw |
                        ControlStyles.SupportsTransparentBackColor, true);
        }
        protected override void OnPaint(PaintEventArgs e) {
                // serurity exception
                IntPtr hdc = e.Graphics.GetHdc();
                e.Graphics.ReleaseHdc(hdc);

                Brush brush = Brushes.White;
                Pen pen = Pens.Black;
                e.Graphics.FillRectangle(brush, ClientRectangle);
                e.Graphics.DrawRectangle(pen, ClientRectangle);
                e.Graphics.DrawString("hello", Font, Brushes.Black,
ClientRectangle);
        }
}

Then it is put inside a user control, which is then embedded in an HTML:

<HTML>
  <BODY bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">
    <OBJECT id="MyControl1" height="200" width="200"
classid="http:WindowsApplication2.exe#WindowsApplication2.UserControl1"
VIEWASTEXT></OBJECT>
  </BODY>
</HTML>

Would you like to take a closer look at this scenario? I could send you a
sample project and screenshots showing the problem.

Thanks



Relevant Pages

  • .net assemblies in cab file
    ... I am deploying a .net assemblies with it's dependent assemblies and a ... .inf (all in a cab file) on a TOMCAT Server. ... Here is the HTML Page excerpt: ...
    (microsoft.public.dotnet.general)
  • Calling dot.net code/assembly from a webpage ?
    ... Suppose I have an html website. ... for example asp.net assemblies ... asp.net thingy which when access is allowed would redirect the user to the ...
    (alt.comp.lang.borland-delphi)
  • Re: Graphics.GetHdc causes InvalidOperationException
    ... > assemblies with MS strongkey is not enough. ... > assemblies which come from MS aren't signed with their key? ... on the client machine. ... Since you're not actually using the GDI device context, ...
    (microsoft.public.dotnet.security)