turhan
turhan

Reputation: 51

System.DirectoryServices.AccountManagement is not supported on this platform

I get this exception when debugging:

System.DirectoryServices.AccountManagement is not supported on this platform.

and call stack starts as:

System.DirectoryServices.AccountManagement.PrincipalContext.PrincipalContext(System.DirectoryServices.AccountManagement.ContextType) in System.DirectoryServices.AccountManagement.notsupported.cs

I am running on Windows, I am targeting:

<TargetFramework>net6.0-windows</TargetFramework>

and I use this package:

<PackageReference Include="System.DirectoryServices.AccountManagement" Version="7.0.0" />

System.DirectoryServices.AccountManagement is supposed to work on Windows but I can not find what makes it think that it is on a different platform.

Any help will be much appreciated!

People have reported this error when using linux or docker deployments but I am using windows 10, and some people report that it is due to using

<TargetFramework>netstandard2.1</TargetFramework>

I have moved all my projects into

<TargetFramework>net6.0-windows</TargetFramework>

but it is still throwing this exception.

Upvotes: 0

Views: 1614

Answers (1)

Milad
Milad

Reputation: 23

Just setting <TargetFramework>net6.0-windows</TargetFramework> alone may not resolve the problem. You also need to specify the RuntimeIdentifier to ensure the correct architecture is targeted.

To fix this, add the following to your .csproj file:

<RuntimeIdentifier>win-x64</RuntimeIdentifier>

or, if targeting 32-bit Windows:

<RuntimeIdentifier>win-x86</RuntimeIdentifier>

Upvotes: 0

Related Questions