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?
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.
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.
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
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.
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.
Having this exact issue as well and workaround didn't solve it.
I'm on Windows btw.
We managed to resolve this issue by marking the common library project as dual-target:
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
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
Most helpful comment
Did you manage to get this working?
We are seeing the exact same issue where we have a dotnet standard dll that calls
GetCurrentonWindowsIdentity. 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.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.