when our code tries to access UserPrincipal.Current, the function returns a GroupPrincipal. The subsequent attempted cast to UserPrincipal fails

Chinthala, Dinesh 0 Reputation points
2024-12-12T17:53:18.9333333+00:00

when our code tries to access UserPrincipal.Current, the function returns a GroupPrincipal. The subsequent attempted cast to UserPrincipal fails. I saw this occur when I saw the stack trace on Ariel’s test machine, on the line of code in the Login Form that accesses the UserPrincipal.

 

We need this object in order to authenticate the Windows user, and get related data such as email address, from it.

 

The information from these bugs indicates this is an issue with dotnet itself. I can’t find any way people are working around this, or have solved it.

 

 Logged bug is here:

 

UserPrincipal.FindByIdentity throws InvalidCastException · Issue #30408 · dotnet/runtime

 

It is also referenced here:

 

UserPrincipal.Current throws InvalidCastException · Issue #38411 · dotnet/runtime

UserPrincipal.Current throws InvalidCastException in User.FindByIdentity · Issue #51744 · dotnet/runtime

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,917 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.