Why is my application coughing up a SecurityException after my code stops running?

Odd exceptions at odd times If you apply a PrincipalPermission attribute to a class in order to restrict the users and/or roles that are permitted to use the class, you may start seeing security exceptions like the following being thrown at unexpected times (like, say, when your application is quitting): System.Security.SecurityException was unhandled Message=”Request for principal permission failed.” Source=”mscorlib” StackTrace: at System.Security.Permissions.PrincipalPermission.ThrowSecurityException() at System.Security.Permissions.PrincipalPermission.Demand() at System.Security.PermissionSet.DemandNonCAS() at YourNamespace.YourClass.Finalize() What’s up with that? The basic gist of the above exception that the demand for your specified PrincipalPermission is failing when the finalizer for your class is invoked. If your class also … Continue reading Why is my application coughing up a SecurityException after my code stops running?