locked
Getting an unexplained SecurityException... RRS feed

  • Question

  • I've been running my application all morning with any problems, and then all of a sudden I started getting this security exception when I run:

    =======================================================================================
    A first chance exception of type 'System.Security.SecurityException' occurred in mscorlib.dll

    Additional information: Request for the permission of type 'System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    =======================================================================================

    I thought the maybe Vista was just wigging out, so I rebooted, but when I tried to run again, I got the same exception. While I hadn't changed anything relevant in the code before the exception started occurring, I decided that just to be sure, I should roll back my code to a previous revision. I reverted back to last week- same exception.

    I put a break point in the constructor for my main ApplicationWindow class, and the exception occurs before I get there. I put a break point in my application constructor and it gets hit prior to the exception, but as soon as I step out of it, the exception fires. What is going on here?

    Thanks,
    --Jeremy

    Wednesday, April 9, 2008 5:50 PM

All replies

  • Hi Jeremy,

     

    First off, I need some information:

     

    1) Where are you running your application from, and has this changed?  (Pick one: Local, UNC path, HTTP Internet/Intranet, HTTPS Internet/Intranet)

     

    2) What is the base class for "my main ApplicationWindow class"???  If it's Window or NavigationWindow, this is the source of your problem, as these cannot be instantiated in partial trust.

     

    3) What type of app are you building?  .xbap, .application, or plain .exe?

     

    4) Is there an inner exception object and/or a callstack you can post?

     

    Finally, the easiest way for me to help you here is if you can email me a repro @ the address listed in my profile.  If that's an option, please send it over.

     

    -Matt

    Wednesday, April 9, 2008 11:12 PM
  • 1) I'm running the application locally- that hasn't changed.
    2) My main ApplicationWindow class derives from Window
    3) It is a plain old .exe
    4) There is no inner exception or call stack.

    --Jeremy


    Wednesday, April 9, 2008 11:17 PM
  • Hi Jeremy,

     

    This is very strange.  Your application can't run in partial trust (the only possible explanation for this exception) if you really are just running an .exe outside of Visual studio, unless you yourself included a special app.config or set up a partial trust AppDomain in code (that's really tricky w/ WPF so I doubt it).

     

    Most likely, you have accidentally gotten the bit flipped to debug with ClickOnce security settings.  Can you get the project properties for your app, go to the "Security" tab, and make sure to uncheck "Enable ClickOnce Security settings" or check the "This is a full trust application" radio button.

     

    You may also want to simply re-create your project if this doesn't solve your issue...  something is very wrong if Visual Studio is starting your app in a partial trust appdomain without you specifying this.

     

    -Matt

    Wednesday, April 9, 2008 11:43 PM
  • Enable ClickOnce is not checked. I can see that the "This is a full trust application" is checked, although it is grayed out. I also did what you suggested and re-created the project and it works for a couple of runs, and then I get the exception again.

    --Jeremy

    Wednesday, April 9, 2008 11:54 PM
  • Another clue- if I rename the directory that my application runs from, it works....
    Thursday, April 10, 2008 12:26 AM
  • That is fascinating.  Can you just send me the project or a minimal repro that does this ?  I suspect something may be very wrong with your VS or .NET Framework install. 

     

    You might also try enabling ClickOnce security settings so that the Full trust radio button is enabled.  Also, does this only repro for F5 scenarios, or even when you double click the .exe outside of the IDE?

     

    Also, if you can try this on another machine that might help...

     

    -Matt

    Thursday, April 10, 2008 12:38 AM
  • I trully don't know what in the hell is going on here. It is now working fine without me changing the directory name. It was doing this earlier today where it would work for a while, then quit, but this time I've restarted the app at least 10 times and it has not quit on me yet.

    If it starts happening again, I'm afraid I can't send you the project, and other WPF projects on my machine work fine, and this project worked fine on another Vista computer as well. For the moment, it is working, though....

    --Jeremy

    Thursday, April 10, 2008 12:44 AM
  • OK, starting to get some more info. The app was working because when I created the new project I forgot to change the CPU target to x86 (I'm running on Vista x64). I'm marshalling code to 32 bit DLLs, so I have to force my project to compile as x86. Once I change the CPU target to x86, I get the exception. I also tried to run the app outside of the debugger, and it fails there too. If I rename the directory though, then I don't....

    I've searched the registry to see if that path somehow got marked for different security permissions, but nothing comes up. Is there somewhere else I can look?

    Thanks,
    --Jeremy


    Thursday, April 10, 2008 12:56 AM
  • I've asked around about this issue, and there's a slight chance you're seeing problems related to Vista's UAC feature that are getting wrapped as security exceptions.  This would be caused by creating your project at a higher integrity level than you are running VIsual studio at, which can lead to snags like this.

     

    The best way to check for this is to download SysInternals Process Monitor and look for "ACCESS DENIED" type errors.  Alternatively, you could just run everything elevated temporarily (right click on VS shortcut, "Run as Administrator", or directly on your .exe) to see if this sorts your problem out.

     

    HTH,

    Matt

     

    Thursday, April 10, 2008 4:37 PM
  • Visual Studio is running already running as an admin, and I have UAC disabled (set to elevate without prompting). I'll check out the sys internals tool and get back to you on what I find...
    Thursday, April 10, 2008 9:53 PM
  • oh, I got the same identical exception. Both on VS2005 and VS2008. VS2003 seems not be affected (when code is identical and compatible across all frameworks).

    When you run an assembly in Debug Mode (F5) that exeception throws. While running without-debug (CTRL + F5) or outside IDE, i.e. double click on assembly, all that works.

    I found a solution unchecking Enable Visual Studio hosting process in Properties > Debug tab. But I dot not understand why.

     

    PS: An alert message box appears when you try this workaround:

      "The security debugging option is set but it requires the Visual Studio hosting process which is unavailable in this  debugging configuration. The security debugging option will be disabled. This option may be re-enabled in the Security property page. The debugging session will continue without security debugging"

     

    Saturday, April 26, 2008 7:39 PM
  • I am also getting this problem running Visual Studio C# 2005 Light edition. I am building it without ClickOnce security enabled and am simply trying to ctrl+F5 or copy the release .exe out and execute, but keep getting security errors as outlined in this thread.

     

    One other funny thing, when I tried to run my released .exe on another machine, it kept failing at the Just In-Time Debugger. When I got login access with Debug permissions it started to work. Why would there be DEBUG info in my released executable?

     

    Regards

    Thursday, May 8, 2008 2:42 AM