Search code examples
c#.nettranslateuser-accounts

NTAccount.Translate Method fails with error Some or all identity references could not be translated


PipeAccessRule par = new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);

This code fails with error:

Some or all identity references could not be translated.

I guess this is because I'm using "Everyone" while launch my app on non-English local. On English system everything is OK.

How to avoid this? Is there some enum describes general user groups?

Stack trace:

at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)    
at System.Security.Principal.NTAccount.Translate(Type targetType)    
at System.Security.AccessControl.CommonObjectSecurity.ModifyAccess(AccessControlModification modification, AccessRule rule, Boolean& modified)    
at System.Security.AccessControl.CommonObjectSecurity.AddAccessRule(AccessRule rule)    
at System.IO.Pipes.PipeSecurity.AddAccessRule(PipeAccessRule rule)    

Solution

  • Solved by using second constructor of PipeAccessRule and SecurityIdentifier instead of string:

    System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
    PipeAccessRule par = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);