The following works on several Server versions of Windows, and on Windows 7 pro and others but on Windows 10 (at least two machines) I get the error: "The system cannot find the file specified.\r\n". The error source is "Active Directory"
System.IO.FileNotFoundException: The system cannot find the file specified.
Stack Trace:
at System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADs.Get(String bstrName)
at System.DirectoryServices.AccountManagement.CredentialValidator.BindSam(String target, String userName, String password)
at System.DirectoryServices.AccountManagement.CredentialValidator.Validate(String userName, String password)
at System.DirectoryServices.AccountManagement.PrincipalContext.ValidateCredentials(String userName, String password)
at IsValidWindowsUser(String userName, String password) in MembershipProvider.cs:line xxx
The following is the minimal amount of code I need to trigger the error. In this case I am using ValidateCredentials() but other operations such as PrincipalSearches also fail with the exact same error.
I have validated that the credentials are valid using LogonUser(); https://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx
bool IsValidWindowsUser(string userName, string password)
{
using (var p = new PrincipalContext(ContextType.Machine))
return p.ValidateCredentials(userName, password);
}
IMPORTANT BIT: I discovered that this WAS working on both Windows 10 systems but since that point both systems had their harddrives replaced by a solidstate drive. The OS moves were done with Disk Imaging software and everything else on the operating system came across intact. I know that the disk/partition signature changed. Could this have broken/damaged then credential stores? A windows 7 pro computer also had its drive replaced but it continues to work as expected.
Another old question that is possibly related is: Validate a users credentials on the local machine
This question also seems to talk about a FileNotFoundException exception with PrincipalContext(ContextType.Machine) but only if there is no network connection. In my case there is always a network connection. I would use LogonUser but I also need to test group membership.