System.Directory Services not supported on windows platform - c#

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

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.

Related

ML.NET: strange runtime error on some machines

I wrote a simple UWP app using the ML.NET framework, and it worked on one of my machines without installing any Nuget packages, without any additional setup etc.
However, on my other machine, after running the application, I get this error:
System.Runtime.InteropServices.COMException: 'Unspecified error
No suitable kernel definition found for op Sub (node Minus675)'
The error happens in this segment of code:
public static async Task<modelModel> CreateFromStreamAsync(IRandomAccessStreamReference stream)
{
modelModel learningModel = new modelModel();
learningModel.model = await LearningModel.LoadFromStreamAsync(stream);
learningModel.session = new LearningModelSession(learningModel.model); // it breaks here
learningModel.binding = new LearningModelBinding(learningModel.session);
return learningModel;
}
In case anyone should ask - yes I have added my .onnx model in the Assets folder. My configuration is: VS 2017, Windows 10 version 1809, build 17763.194, and I have Windows 10 SDK version 10.0.17763.132. I have tried installing the Visual Studio Tools for AI and ML.NET Templates VS extensions, but it didn't help.

Discover the version number of another package

The IoT Core application I'm working on needs to know the (package) version of another application.
Is it possible to find out the version of another app (without needing the admin password as in the example below)?
Unfortunately AppDiagnosticInfo doesn't provide this information (it provides package family name).
I know this is possible with Device Portal REST api, but this requires the device admin password which is not suitable for production scenarios.
//Import WindowsDevicePortalWrapper with NuGet
using Windows.System.Diagnostics.DevicePortal;
(...)
var devicePortalConnection1 = new DefaultDevicePortalConnection(
"http://127.0.0.1:8080",
"administrator",
"my device administrator password");
var portal = new DevicePortal(devicePortalConnection1);
var packages = await portal.GetInstalledAppPackagesAsync();
You can use PackageManager to get the installed packages version. It does not need username and password,but it runs on device locally.
Please refer to below code.
Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();
IEnumerable<Windows.ApplicationModel.Package> packages = (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackages();
foreach(var pkg in packages)
{
var version = pkg.Id.Version;
Debug.WriteLine(string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision));
}
To run above code, you also need to add a restricted capability to the Package.appxmanifest. Had to add a new namespace at the top of the file:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
and add the following to the Capabilties tag.
<rescap:Capability Name="packageQuery" />
You may need to add the 'rescap' namespace to the Ignorable list as per this information.

How to undo changes of framework change?

Recently, I've been working on a project with Access database, but since the deployment would be on a XP computer, I tried changing the .NET Framework from 4.5.1 to 4.
Since then the connection fails to open, and continues to fail even tough I changed it back to 4.5.1.
con.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source = " + Localexe + #"/Database.accdb";
try
{
con.Open();
}
catch (Exception x)
{
}
It says that:
provider 'Microsoft.ACE.OLEDB.12.0' could not be found on the local
machine
I tried opening a new project and seeing if there were any References that got lost on the process but that didn't seem to work.
What is your OS and its bit? what is your access bit? x86 or x64?
anyway pls try :
DefaultAppPool and Classic .NET AppPool (find these path) - right click - 32bit app enable(true)...after this , right click and restart.
I guess it works.

Running SSIS Package from WinForms app - Gnarly Error

I have a winforms application that makes use of Microsoft.SqlServer.ManagedDTS to load and execute an SSIS package. When running locally in debug and when installed the package runs fine, when installed on a dev server the package runs fine. When deployed onto a live server I get the following error.
I'm running out of ideas of what to check, I don't want to move away from using this method of executing my package as this adds further complication to the application that we really don't want to introduce. Any thoughts?
For clarity I have checked:
SSIS is installed and is the same version (Windows/SQL Server 2008)
I added the following app.config key following some google searching useLegacyV2RuntimeActivationPolicy="true"
Tried compiling as a 32-bit and 64-bit application
Ensured that the DLL is registered in the GAC on the target machine
All permissions are the same across the two boxes
The extract of source code that is throwing the error is as follows:
var app = new Microsoft.SqlServer.Dts.Runtime.Application();
var pkg = app.LoadPackage(strSSISPath, null);
pkg.ImportConfigurationFile(strSSISConfig);
var result = pkg.Execute();
if (result.Equals(DTSExecResult.Success))
{
string strMsg = strMHType + " extract completed successfully.";
MessageBox.Show(strMsg, strMHType, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
foreach (var err in pkgMHMDS.Errors)
{
MessageBox.Show(err.Description, strMHType, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show(strMHType + #" extract failed!", strMHType, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
pkgMHMDS.Dispose();
The error that we see (the COM class error) is caused because the version of the Microsoft.SqlServer.ManagedDTS dll is not installed on the target machine. Whilst we did install the dll into the GAC we couldn’t work round the error because Integration Services is a server component and is not redistributable to client computers. The error isn’t terribly informative but essentially what it is trying to say is that it is trying to load an assembly who’s address is stored in the registry key which is created when installing the Client Tools SDK.

No solution for 'Microsoft.ACE.OLEDB.12.0' error

I have a problem with an MVC C# application in one controller.
The following code continues to give the error:
*The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.*
The code below:
var excel = new ExcelQueryFactory("~/App_Data/uploads/" + tempName);
var usersForImport = from c in excel.Worksheet<User>()
select c;
int count = usersForImport.Count();
for (int i = 0; i < count; i++)
{
User user = new User();
user = usersForImport.Skip(i).First();
db.Users.Add(user);
db.SaveChanges();
}
I have tried 2 solutions from previous posts, as I thought this problem was identical, but they do not solve the problem.
The two solutions I have tried are to install the Microsoft Access Database Engine or set the target platform for x86.
The code relies on 'linqtoexcel' package.
Has anyone else run into these problems? Any solutions?
For 64-bit apps, there are two versions of the ACE driver available:
http://www.microsoft.com/en-us/download/details.aspx?id=23734 for Office 2007
http://www.microsoft.com/en-us/download/details.aspx?id=13255 for Office 2010
I believe the Office 2007 version has the ProgId 'Microsoft.ACE.OLEDB.12.0', so I would try this one rather than Office 2010, which I believe has the ProgId 'Microsoft.ACE.OLEDB.14.0'.
From your description, it looks like the linqtoexcel package might depend on the Office 2007 version.
I have solved this in properties of the project, in the Build Tab.
I have changed the platform target from x64 to x86

Categories

Resources