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.
System.PlatformNotSupportedException: System.DirectoryServices is not supported
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?
-
Michael Taylor 57,216 Reputation points
2022-05-17T21:38:17.73+00:00
2 additional answers
Sort by: Most helpful
-
Limitless Technology 39,851 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- 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.--
-
Boettcher, Mark D 0 Reputation points
2025-03-07T18:54:48.5966667+00:00 In Visual Studio v2022, even though I had tried uninstalling/re-installing System.DirectoryServices.Protocols different ways: via the NuGet UI, via the NuGet Mgr Console, or by removing that reference in the package.config and <project>.csproj files and then re-adding it, updating my registry for a binding issue, rebooting, starting/stopping VS 2022, I found that I when I added
<add assembly="System.DirectoryServices.Protocols, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
inside of:
<compilation debug="true" targetFramework="4.7.2" batch="false">
<assemblies>
....
</assemblies>
</compilation>
to my web.config. Once I did that, restarted VS and started typing "@using System.DirectoryServices." in my .cshtml file, I then saw Protocols show up as a selectable method. That fixed it for me.