问题
I have an application that suddenly started crashing when it is shutting down with the following error in the Event Log:
Application: App.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
Stack:
at System.Security.AccessControl.Privilege.Revert()
at System.Security.AccessControl.Privilege.Finalize()
I did some digging in the .NET reference source for that method and it appears to be the exception thrown at the bottom. It can't be the first InvalidOperationException
because it does not contain any message, the one at the end of the method throws a blank one so it has to be the match.
The call to AdjustTokenPrivileges
(P/Invoke) is failing and the checks do not find an expected error code:
if ( error == Win32Native.ERROR_NOT_ENOUGH_MEMORY )
{
throw new OutOfMemoryException();
}
else if ( error == Win32Native.ERROR_ACCESS_DENIED )
{
throw new UnauthorizedAccessException();
}
else if ( error != 0 )
{
Contract.Assert( false, string.Format( CultureInfo.InvariantCulture, "AdjustTokenPrivileges() failed with unrecognized error code {0}", error ));
throw new InvalidOperationException();
}
The documentation on this function doesn't highlight anything obvious with regard to what may be going wrong either.
The only recent changes to the application included adding a basic self-hosted WCF end-point in the application (named pipes) so I'm struggling to understand why this would suddenly occur because of that. It's not disposable either so I'm really not in control of when this gets called.
Could anyone tell me where I could find the error code since it is not included in the exception that is thrown? I would also appreciate any explanation/speculation as to why the destructor of this class is getting called when I don't instantiate access control classes myself. Is WCF doing something with access tokens? UAC is disabled and I am a local administrator on the machine running the application.
来源:https://stackoverflow.com/questions/22525917/how-to-debug-system-invalidoperationexception-in-system-security-accesscontrol-p