when our code tries to access UserPrincipal.Current, the function returns a GroupPrincipal. The subsequent attempted cast to UserPrincipal fails
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