Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread.CurrentPrincipal throws PlatformNotSupportedException on .NET Core 3.x #5583

Closed
bording opened this issue Feb 17, 2020 · 0 comments · Fixed by #5584
Closed

Thread.CurrentPrincipal throws PlatformNotSupportedException on .NET Core 3.x #5583

bording opened this issue Feb 17, 2020 · 0 comments · Fixed by #5584

Comments

@bording
Copy link
Member

bording commented Feb 17, 2020

We're currently setting a WindowsPrincipal principal policy during endpoint startup, even when we are running on non-Windows OSes.

This is relatively harmless when using .NET Core 2.x because the current principal, for example via Thread.CurrentPrincipal, will be null when running on non-Windows OSes.

However, when using .NET Core 3.x, this presents a bigger problem. Accessing the principal when it is a WindowsPrincipal on a non-Windows OS instead throws a PlatformNotSupportedException.

The way to fix this with the least impact would to call AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal) only when we are running on Windows since this will maintain the .NET Core 2.x behavior of getting a null value from things like Thread.CurrentPrincipal.

Who's affected

Anyone using .NET Core 3.x on macOS or Linux and accesses Thread.CurrentPrincipal in their code.

Symptoms

After starting the endpoint, getting the value of Thread.CurrentPrincipal will throw a PlatformNotSupportedException.

Backported to

@bording bording changed the title Setting a WindowsPrincipal on non-Windows OSes is problematic Setting a WindowsPrincipal on non-Windows OSes can throw PlatformNotSupportedException Feb 17, 2020
@bording bording changed the title Setting a WindowsPrincipal on non-Windows OSes can throw PlatformNotSupportedException Accessing Thread.CurrentPrincipal will throw PlatformNotSupportedException on .NET Core 3.x Feb 17, 2020
@bording bording changed the title Accessing Thread.CurrentPrincipal will throw PlatformNotSupportedException on .NET Core 3.x Thread.CurrentPrincipal will throw PlatformNotSupportedException on .NET Core 3.x Feb 17, 2020
@bording bording changed the title Thread.CurrentPrincipal will throw PlatformNotSupportedException on .NET Core 3.x Thread.CurrentPrincipal throws PlatformNotSupportedException on .NET Core 3.x Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant