title: .Net Role Authentication PrincipalPermission fails
body: <p>I have a vb.net 3.5 application using PrincipalPermission class to ensure a user is a member of a role. The code works for some groups in Active Directory domain but not others. 
  At first I thought the space was an issue but I checked 'Domain Users' which worked. Running this code I am a member of App Group. </p>
  
  <pre><code>Imports System.Security
  Imports System.Security.Principal
  Imports System.Security.Permissions
  
      Private Function DemandSecurity() As Boolean
          AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal)
          Dim principalGroup As New PrincipalPermission(Nothing, "App Group")
          Try
              principalGroup.Demand()
              Debug.Print("Demanding pricipal permissions for current user on 'App Group' role succeeded. ")
          Catch secEx As SecurityException
              Debug.Print("Security Exception - Demanding pricipal permissions for current user on 'App Group' role failed. ")
  
              Application.DoEvents()
              MessageBox.Show("Permission denied. Output: " &amp; vbNewLine &amp; secEx.ToString, "App - Security Exception", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
  
              Return False
              Exit Function
          End Try
          Return True
      End Function
  </code></pre>
  
  <p>The error output from secEx.ToString is </p>
  
  <blockquote>
    <p>"System.Security.SecurityException: Request for principal permission failed.
       at System.Security.Permissions.PrincipalPermission.ThrowSecurityException()
       at System.Security.Permissions.PrincipalPermission.Demand()
       at App.My.MyApplication.DemandSecurity() in C:\Documents and Settings\me\My Documents\Visual Studio 2008\Projects\App\App\ApplicationEvents.vb:line 28</p>
    
    <p>The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Security.Permissions.PrincipalPermission</p>
    
    <p>The first permission that failed was:
    IPermission class="System.Security.Permissions.PrincipalPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1">
    Identity Authenticated="true"
    Role="App Group"/>
    </p>
    
    <p>The demand was for:
    IPermission class="System.Security.Permissions.PrincipalPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    version="1">
    Identity Authenticated="true"
    Role="App Group"/>
    </p>
    
    <p>The assembly or AppDomain that failed was:
    mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"</p>
  </blockquote>
  
  <p>Let me know if I need to include anything else. </p>