Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

System.PlatformNotSupportedException: 'Windows Principal functionality is not supported on this platform.' #1279

Closed
Rajesht2305 opened this issue Jun 25, 2019 · 13 comments

Comments

@Rajesht2305
Copy link

Rajesht2305 commented Jun 25, 2019

Hello Team,
we are using .net standard libraries in .net framework application. trying to access network share by using Impersonation but windows identity is throwing not supported exception.

Code snippet:

public void RunImpersonated(Action action)
{
using (WindowsIdentity identity = new WindowsIdentity(_token))
{
WindowsIdentity.RunImpersonated(identity.AccessToken, action);
//_context = identity.Impersonate();
}
}

.net standard dll versions:
.net standard -version 2.0
System.Security.Principal.Windows - version: 4.1.1.1
.net framework version -4.7.2

any support to resolve this issue?

@Rajesht2305 Rajesht2305 changed the title System.PlatformNotSupportedException System.PlatformNotSupportedException: 'Windows Principal functionality is not supported on this platform.' Jun 25, 2019
@wtgodbe wtgodbe added this to the .NET Standard vNext milestone Jun 25, 2019
@joperezr
Copy link
Member

This should work just fine in .NET Framework. We throw PNSE on Linux, but we do have implementation for Windows. In .NET Framework specifically, our System.Security.Pincipal.WIndows dll should just type forward to mscorlib and use the implementation that comes inbox for this. Can you share more info about how is it that you are referencing WindowsIdentity? Also, if you are targetting .NET Framework, why are you adding a reference to the System.Security.Principal.Windows package? You shouldn't need that since the types you would need live in mscorlib.

@Rajesht2305
Copy link
Author

Hello joperezr,
Yes it is working fine with .net framework. but i'm facing issue where share access logic is .net standard library and exposed an API to use it in .netFramework.

If the same API is accessing from .net core application it is working fine. please have a look into the attachment.

standardLibrary.zip

@joperezr
Copy link
Member

joperezr commented Jun 27, 2019

Is the problem that you are seeing happening in ConsoleApp1 of the attached? If so, I did notice that in that project you are missing a property that is required when referencing sdk-style projects from a .NET Framework app. Try setting the following in your ConsoleApp1.csproj:

<PropertyGroup>
  <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

After that, run msbuild /t:Restore ConsoleApp1.csproj and then rebuild msbuild /t:Rebuild ConsoleApp1.csproj

@sami016
Copy link

sami016 commented Sep 23, 2019

Hello joperezr,
Yes it is working fine with .net framework. but i'm facing issue where share access logic is .net standard library and exposed an API to use it in .netFramework.

If the same API is accessing from .net core application it is working fine. please have a look into the attachment.

standardLibrary.zip

Did you manage to get this working?

We are seeing the exact same issue where we have a dotnet standard dll that calls GetCurrent on WindowsIdentity. It works fine in a dotnet core application, but as soon as you import it into a dotnet framework application is seems to give the error described in the original post.

Exception thrown: 'System.PlatformNotSupportedException' in System.Security.Principal.Windows.dll
Windows Principal functionality is not supported on this platform.

This is using .net framework 4.7.2 referencing a .net standard 2.0 common library.

The PackageReference suggestion above sadly did not have any effect on this.

@Jmales
Copy link

Jmales commented Sep 24, 2019

Having this exact issue as well and workaround didn't solve it.

I'm on Windows btw.

@sami016
Copy link

sami016 commented Oct 15, 2019

We managed to resolve this issue by marking the common library project as dual-target:

<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>

@KamranShahid
Copy link

I am getting this error when trying to debug a asp.net core 3.1 application with log4net in WSL2
Details are https://stackoverflow.com/questions/64049482/log4net-windows-principal-functionality-is-not-supported-on-this-platform-with

@MyoMinLin
Copy link

MyoMinLin commented Nov 2, 2021

I am also having the same issue.
Trying multiple target frameworks is also not working for me.
How to solve it without upgrading any Framework?

@KamranShahid
Copy link

@MyoMinLin
upgraded the log4net. they have resolved this issue in the latest version. also always try to debug in WSL option so that you get real experience how this will behave in linux environment

@brandonros
Copy link

Is the bottom line that Docker containers running dotnetcoreapp3.1 are not allowed to call anything with WindowsIdentity identity? Is that not a cross-platform supported API?

@bartonjs
Copy link
Member

@brandonros If you're using Windows on Docker then I'd expect it to work. If you're using any other OS, I'd expect it to fail. Linux doesn't have a notion of a WindowsIdentity.

@KamranShahid
Copy link

Is the bottom line that Docker containers running dotnetcoreapp3.1 are not allowed to call anything with WindowsIdentity identity? Is that not a cross-platform supported API?

Yes this WindowsIdentity Api seems to be specific to windows .
Certain api's/technology within .net is specific to windows which will obviously not work on linux/mac e.t.c.

@terrajobst
Copy link
Member

I can't repro this. Please let us know if this is not working.

@terrajobst terrajobst closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants