TechStriker
TechStriker

Reputation: 71

System.Directory Services not supported on windows platform

i am quite new to software development as well as to this site. My question is about the System.DirectoryServices development on windows. I started a normal Visual Studio 2019 c# .net 5.0 project and added the references for the .dll file as well as the nuget packages for it and even the windows compatibility package. I also changed the target framework from .net5.0 to .net5.0-windows, but it still says "System.DirectoryServices is not supported on this platform" Every time i try to create a DirectoryEntry it gives me the mentioned message above.

Following my Code to generate a User:

try
            {
                DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
                DirectoryEntry NewUser = AD.Children.Add(du.Name, "user");
                NewUser.Invoke("SetPassword", new object[] { du.password });
                NewUser.Invoke("Put", new object[] { "Description", "Test User from .NET" });
                NewUser.CommitChanges();
                DirectoryEntry grp;

                grp = AD.Children.Find("Administrators", "group");
                if (grp != null) { grp.Invoke("Add", new object[] { NewUser.Path.ToString() }); }
                Console.WriteLine("Account Created Successfully");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

Can someone help me? My goal is to simply create a new local user on a windows system.

Thank you very much in advance!

I followed the ideas mentioned here: https://learn.microsoft.com/en-us/answers/questions/853176/systemplatformnotsupportedexception-systemdirector.html

Upvotes: 3

Views: 8684

Answers (2)

Imran
Imran

Reputation: 11

I had the same issue and was able to make it work with System.DirectoryServices.AccountManagement v6.0.0 on .NET Core 5.0. Unfortunately, at this time, I cannot upgrade to Visual Studio 2022, which supports .NET 6.0 and above.

Upvotes: 1

TechStriker
TechStriker

Reputation: 71

Okay apparently my problem is just as simple as it is... As mentioned i am quite new.. "System.DirectoryService" is not supported on this platform means, that the framework version i am developing on does not support the .dll i was importing.

The solution: I installed VS2022, started a new project with 6.0 .net framework and loaded the nuget packages for "System.DirectoryServices.AccountManagement" & "System.DirectoryServices.Protocols" and now it works fine.

Upvotes: 4

Related Questions