hwo to set to avoid the SecurityException ...?

************** Exception Text **************
System.Security.SecurityException: Request for the permission of type System.Windows.Forms.SafeNativeMethods.IFont.GetHFont()
at System.Windows.Forms.Control.ActiveXImpl.get_AmbientFont()
at System.Windows.Forms.Control.get_Font()
at System.Windows.Forms.Control.GetParentFont()
at System.Windows.Forms.Control.get_Font()
at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.CommonLayout()
********************************

I'v used ".NET Framework 2.0 Configuration" tool,
new a Permission set and set permisson "User Interface" "Grant Assemblies unrestriced access to user interface",
still got the exception.
( If set Permission set to "FullTrust", then ok! )
What specific perssion should I set?

Thanks.

*****************************
Exception Detail:
(a simple control, with a button docked top,
host in IE)

See the end of this message, instead of this dialog box, for details on invoking
just-in-time (JIT) debugging.

************** Exception Text **************
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Windows.Forms.SafeNativeMethods.IFont.GetHFont()
at System.Windows.Forms.Control.ActiveXImpl.get_AmbientFont()
at System.Windows.Forms.Control.get_Font()
at System.Windows.Forms.Control.GetParentFont()
at System.Windows.Forms.Control.get_Font()
at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.CommonLayout()
at System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintWorker(PaintEventArgs e, Boolean up, CheckState state)
at System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintDown(PaintEventArgs e, CheckState state)
at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.Paint(PaintEventArgs pevent)
at System.Windows.Forms.ButtonBase.OnPaint(PaintEventArgs pevent)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The action that failed was:
Demand
The type of the first permission that failed was:
System.Security.Permissions.SecurityPermission


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///D:/WINDOWS/Microsoft.NET/Framework/v2.0.50215/mscorlib.dll
-
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///D:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
-
Simple
Assembly Version: 1.0.0.0
Win32 Version: n/a
CodeBase:http://127.0.0.1/exp/dotnetfx/iecontrol/simple/Simple.dll
-
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///D:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
-
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50215.44 (beta2.050215-4400)
CodeBase:file:///D:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
-
Microsoft.mshtml
Assembly Version: 7.0.3300.0
Win32 Version: 7.0.3300.0
CodeBase:file:///D:/WINDOWS/assembly/GAC/Microsoft.mshtml/7.0.3300.0__b03f5f7f11d50a3a/Microsoft.mshtml.dll
-

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.


[6023 byte] By [ec] at [2008-2-13]
# 1
Hi,

Need more details. Are you trying to host a Windows Forms control in IE? The error message gives the impression of something like that: "a simple control, with a button docked top, host in IE"

The permissions also depend on other system resources which you are using such as FileSystem or Registry also. Please provide more details on if your app uses any such resources.

Regards,
Vikram

Vikram at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

Yes, I'm trying to host a windows forms control in IE.

My app is simple, just for test,
did not use other rescource...
******* here is my source
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace com.infocloud.exp.iecontrol.Simple
{
public class Class1:Control
{
Button btn1;
public Class1()
{
this.BackColor = System.Drawing.Color.Blue;
btn1 = new Button();
btn1.AutoSize = false;
btn1.Text = "AAA";
Controls.Add(btn1);
}
}
}
*********************

and the control is displayed ok at first,
after clock somewhere,
the exception will appear...
and the button control will show big red "X", (no text on it)
You can view the webpage here. (and src.zip)
http://www.infocloud.com/exp/dotnetfx/iecontrol/simple/

Thanks.

ec at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
I'v assigned "Security" to Permisson set,
and check "Allow calls to unmanaged assemblies",
then seems ok!

But, is it resonable?
can unmanaged assemblies do anything?
I'v test more,

AssemblyInfo.cs
//[assembly: ComVisible(false)]

and use html script to set Control Width,
http://127.0.0.1/exp/dotnetfx/iecontrol/simple1/

when chage ie's size (then chang control size),
the exception raised. (eaiser to reproduce)
Thanks.

ec at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4
Hi,

Have you configured the IE browser for Security?

Take a look at the following samples:
Using Windows Forms Controls in Internet Explorer
http://windowsforms.net/articles/iesourcing.aspx

Hosting .NET Windows Forms Controls in IE
http://www.15seconds.com/issue/030610.htm

Regards,
Vikram

Vikram at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5
I'v rebuild the project by VS2003,
and it is ok ...... with .net framework 1.1 installed.
(I'v tried with 1.1 and 2.0b2 installed,
and a machine only with 1.1 installed.)

but if only vs2005b2 installed, got the exception.

So, I don't think it's problem about IE or Security configuation.....

ec at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 6
Review the exception carefully...

************** Exception Text **************
System.Security.SecurityException: Request for the permission of type System.Windows.Forms.SafeNativeMethods.IFont.GetHFont()
at System.Windows.Forms.Control.ActiveXImpl.get_AmbientFont()
at System.Windows.Forms.Control.get_Font()
at System.Windows.Forms.Control.GetParentFont()
at System.Windows.Forms.Control.get_Font()
at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.CommonLayout()
********************************
Is the "SafeNativeMethods.IFont.GetHFont" unmanaged code?
so the exception raised?
Is there a security setting to allow run certern unmanaged code such as "Safe" Prefix's method ^^,
not all unmanaged code?
I'v expilcit set the Control's font to avoid this situation,
this.Font=new System.Drawing.Font("Times New Roman", 7.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(136)));
and seems work fine.

ec at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified