PrincipalPermission and Finalizers

Nicole Calinoiu, one of our developer security MVPs, has just posted a good description of the problems that occur when using PrincipalPermission with impersonation and finalizers.  The key thing to take away from this is that impersonation occurs on a per-thread basis and finalizers run on a thread that the GC controls, not on the main thread of your application.  This means that if you're impersonating on your application's thread, your finalizers will not run under the impersonated context.

While Nicole gives a general solution to the problem, she also points out that if you're doing something that requires impersonation on the finalizer thread you might want to think about the design of your class.  Definitely worth a read.