none
Random System.Security.SecurityException being thrown by application RRS feed

  • Question

  • I have a customer using a C# application who is experienceing random crashes. The stack trace from these crashes looks like:

    System.Security.SecurityException:
    Request for the permission of type 'System.Security.Permissions.UIPermission,
    mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    failed.
    at
    System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm,
    PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
    SecurityAction action, Object demand, IPermission permThatFailed)
    at
    System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object
    assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle
    rmh, SecurityAction action, Object demand, IPermission permThatFailed)
    at
    System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet grantedSet,
    PermissionSet refusedSet, CodeAccessPermission demand, PermissionToken
    permToken, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction
    action, Boolean throwException)
    at
    System.Security.CodeAccessSecurityEngine.CheckHelper(CompressedStack cs,
    PermissionSet grantedSet, PermissionSet refusedSet, CodeAccessPermission
    demand, PermissionToken permToken, RuntimeMethodHandle rmh, Assembly asm,
    SecurityAction action)
    at
    System.Security.CodeAccessSecurityEngine.Check(Object demand,
    StackCrawlMark& stackMark, Boolean isPermSet)
    at
    System.Security.CodeAccessPermission.Demand()
    at System.Windows.Forms.Control.get_Parent()
    at
    DevExpress.XtraEditors.BaseControl.OnPaint(PaintEventArgs e)
    at
    DevExpress.XtraEditors.BaseButton.OnPaint(PaintEventArgs e)
    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
    DevExpress.Utils.Controls.ControlBase.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.UIPermission

    It seems that the WmPaint() method of a third party button control is referencing the control's parent, and that action is causing a request for UIPermission, which is failing. From what I can tell, The UIPermission controls access to the user interface and the clipboard. I don't see any reason why this would work almost all of the time, but sometimes fail.

    We've tried changing the settings under the .NET Framework 2.0 Configuration tool to make sure that the code has full trust to run, but this has had no effect on the error occuring. All the assemblies are on the local machine (DevExpress assemblies in the GAC, and other assemblies in the application's installation directory.)

    The customer reports that they can go for weeks without having any problems, but once the error happens it will happen again and again for the rest of that day.

    Other customers do not see this issue, and we have not been able to reproduce the problem locally. They have tried to install the application on different machines, but the problem still happens for them.

    The value of the System.Security.SecurityException.Zone property on the exception is "NoZone".

    The app is using .NET 2.0.

    Does anybody have any idea what could be the cause of the issue, and what can be done to stop it from happening? I've seen other people asking similar questions, but many of those involve running code over a network connection, and I see none where everything works fine most of the time and then fails seemingly randomly.

    Thursday, April 4, 2013 10:42 PM

All replies

  • When the error occurs check the Task Manager for a process that didn't close.  You also may want to check the Event viewer (control Panel - Adminstrator tools) for additional error messages.  th ecode is really getting the handle of the parent (a window) when the failure is ocuring.  Often these type errors when the window does not have the focus.  Another window may temporarily grab the focus or another window was on top of the current window.  This is normally a threading issue and maybe putting a lock on the process may fix the problem.

    jdweng

    Friday, April 5, 2013 3:39 AM
  • Hi Dconnor,

    >>It seems that the WmPaint() method of a third party button control is referencing the control's parent,

    It seems this issue is related to the third party button.

    Would you like to check the permission before the button WmPaint to check where it lose, or where it demand.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, April 7, 2013 11:55 PM
    Moderator
  • I've checked task manager and event viewer, but didn't see anything that looked like it was related. I don't see how it could be a threading issue, as the exeption is occuring on the UI thread, and controls should be able to paint themselves even if another window or control has focus. Can you point me towards an example of the kind of thing you're talking about? Maybe some sample code that demonstrats what you mean?
    Monday, April 8, 2013 4:40 AM
  • The code for the thrid party control references its Parent, which is where the problem manifests itself. the get_Parent() method is inside system.Windows.Forms.Controls, which is where the demand for the permission takes place. As this is in a core pirce of dotnet functionality, I can only assume that it's doing something sane.

    Is there some way to query code access security to find out why a particular permission is denied? I don't see any obvious reason why it would be in any of the code I look at.

    Monday, April 8, 2013 4:46 AM
  • Try these user32.dll functions from the pinvoke website to see if they help find the problem.

    Get Last Error

    http://www.pinvoke.net/default.aspx/user32/GetLastError.html

    Get Parent

    http://www.pinvoke.net/default.aspx/user32/GetParent.html


    jdweng

    Monday, April 8, 2013 9:33 AM