System.PlatformNotSupportedException: System.DirectoryServices is not supported

ask 21 Reputation points
2022-05-17T18:48:14.787+00:00

I am building a .net 5 core asp.net app and developing on a windows maching. I am deploying to a Windows 2019 server with IIS. I installed the hosting bundle and the runtime. I can run the app fine until I add in ldap authentication. I normally use System.DirectoryServices. It runs fine locally, but on the server I get the exception:

Category: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware
System.PlatformNotSupportedException: System.DirectoryServices is not supported on this platform.

I got warnings while developing that DirectorySearcher and DirectoryEntry were only available on windows. I thought no problem I am devving and deploying on windows. So why would I be getting this error. Am I missing a configuation somewhere?

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,820 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 47,711 Reputation points
    2022-05-17T21:38:17.73+00:00

    Ensure your web app is building against net6.0-windows and not just net6.0 or something else. If you're getting warnings then that is a problem.


1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,336 Reputation points
    2022-05-25T07:21:05.383+00:00

    Hi,

    Thanks for writing and we are happy to help you regarding your query related to .Net Core application.

    Based on the compatibility pack list, your case should work fine in Windows platform,.
    https://devblogs.microsoft.com/dotnet/announcing-the-windows-compatibility-pack-for-net-core/

    Could you please try following options to resolve the issue?

    1.In case, you see warnings for a platform-specific APIs usage even if you're targeting that platform, , enable the AssemblyInfo.cs file generation or add the attribute manually in your project.
    Please refer the following link for additional info,
    https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1416

    1. Try using the Windows compatibility pack. https://learn.microsoft.com/en-us/dotnet/core/porting/windows-compat-pack

    3.Try using following library for LDAP - *************************************************************

    Besides, here's a document about deploying .NET Core application.

    .NET Core application deployment - https://learn.microsoft.com/en-us/dotnet/core/deploying/

    Hope it could be helpful.


    --If the reply is helpful, please Upvote and Accept as answer.--

    0 comments No comments