protecting a class declarativly (going mad)



hi there! according to msdn (link at bottom) i should be able to
protect a whole class declaratively as above. However i keep getting
'request for principal permissions failed' exceptions.

in the msdn article a reference is made to include
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
in your code to set the appdomain principal.I can understand how to
use setprincipalpolicy to protect a method declaratively (working code
example at bottom)

but how do i protect a CLASS?

the question is where & how to SetPrincipalPolicy Declaratively? is
there an attribute in assemblyinfo.vb for this?

many thanks,
X



a)msdn link:
http://msdn2.microsoft.com/en-us/library/system.security.permissions.principalpermissionattribute.aspx

b)Protecting a class - this doesnt work (& i tried
role:="administrators", name:="administrator" etc)
<PrincipalPermissionAttribute(SecurityAction.Demand, Role:="BUILTIN
\Administrators") _
Public Class Form1 Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Messagebox("form should load if user is admin")
End Sub


c)Protecting a method - this works ok
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
dowork()
End Sub
<PrincipalPermissionAttribute(SecurityAction.Demand, Role:="BUILTIN
\Administrators")> Sub dowork()
MessageBox.Show("protected")
End Sub
end class

.