I am using the following to retrieve a user's email address on Windows which works for me and most of our clients, but one client is running into an error for multiple users.
var email = UserPrincipal.Current.EmailAddress;
The error: "The specified directory service attribute or value does not exist."
We have verified the correct email is populated in the "mail" attribute on the user's AD object.
I have researched the error and found multiple sources stating this error is likely caused by insufficient active directory permissions, but I have been unable to track down what specifically we need to change.
For testing, I have been using the follow in PowerShell, and the users experiencing the issue get the same error. When I run the commands in PowerShell it returns my email address as expected:
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
[System.DirectoryServices.AccountManagement.UserPrincipal]::Current.EmailAddress
A code change is not possible, so I am wondering what, if any changes we could make to active directory settings that would allow this code to run without error?