question

ask-2849 avatar image
0 Votes"
ask-2849 asked LimitlessTechnology-2700 answered

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?

windows-active-directory
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered cooldadtx commented

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Would this work with net5.0-windows? Also, how do you build against a specifc target framework in Visual Studio by its moniker? Or do I have to use the command line? Thanks.

0 Votes 0 ·

It should work with .NET 5 but .NET 5 is out of support so you shouldn't be building against that. Use .NET 6. Setting up the target framework requires that you select the project node in Solution Explorer. It should then throw you into the built in editor for the project file. Currently there will be a line that says something like <TargetFramework>net5.0</TargetFramework>. Change that line to be <TargetFramework>net5.0-windows</TargetFramework>.

Alternatively you can right click the project and select Properties and then set the framework in the GUI but it takes longer.

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

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://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1416

  1. Try using the Windows compatibility pack. https://docs.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://docs.microsoft.com/en-us/dotnet/core/deploying/

Hope it could be helpful.



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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.