Hi,
We have written a simple user control which we are hosting in IE which
allows users to upload files by browsing or drag / droping files onto it. We
have done a fair amount of work before with hosted controls in IE and have an
MSI which is installed for all users which gives Full Trust to all our
controls.
However, when the control is loaded we get an exception
System.InvalidOperationException: DragDrop registration failed. --->
System.Security.SecurityException: Request for the permission of type
System.Security.Permissions.UIPermission, mscorlib, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet
grantedSet, PermissionSet deniedSet, CodeAccessPermission demand,
PermissionToken permToken)
at System.Security.CodeAccessSecurityEngine.Check(PermissionToken
permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32
checkFrames, Int32 unrestrictedOverride)
at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission
cap, StackCrawlMark& stackMark)
at System.Security.CodeAccessPermission.Demand()
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
--- End of inner exception stack trace ---
at System.Windows.Forms.Control.SetAcceptDrops(Boolean accept)
at System.Windows.Forms.Control.OnHandleCreated(EventArgs e)
at Microsoft.Ink.InkPicture.OnHandleCreated(EventArgs e)
at System.Windows.Forms.Control.WmCreate(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
However, when attaching the debugger to IE, this exception is not thrown
until AFTER the code which registers the drag drop events has appeared to run
successfully. I.e. I can set happily through the constructor and the
AllowDrop = true statement with no exception being thrown. The exception
happens after I step out of our code and there is no trace back to our code.
I have made sure that any calls to AllowDrop and references to the drag drop
events / handlers are all asserting UIPermission.
On searching newsgroups it seems some people have had issues like this
resolved by fixing their application to a single thread by calling:
System.Threading.Thread.CurrentThread.ApartmentState =
System.Threading.ApartmentState.STA;
this seems to have no effect for us and I think it may call wierdness in IE.
Any suggestions would be very gratefully recieved!
Will Holley - 30 Aug 2005 12:46 GMT
Ok problem solved - I was being dumb. All that was required was to override
the OnHandleCreated method from InkPicture with:
protected override void OnHandleCreated(EventArgs e)
{
new UIPermission(PermissionState.Unrestricted).Assert();
base.OnHandleCreated (e);
CodeAccessPermission.RevertAssert();
}
> Hi,
>
[quoted text clipped - 48 lines]
> this seems to have no effect for us and I think it may call wierdness in IE.
> Any suggestions would be very gratefully recieved!