I start encounter a new runtime System.IO.FileNotFoundException exception after upgrade my system from win7 x64 to win 10 x64.
I have the following code that works perfect until now:
{
PrincipalContext pc = new PrincipalContext(ContextType.Machine, Environment.MachineName);
UserPrincipal usrPrin = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, Username);
if (usrPrin == null) // No user exist
{
return -1;
}
// user exist
return 1;
}
I always built the project using the platform target: x86, when I run the application, I get the exception when call UserPrincipal.FindByIdentity.
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.DirectoryServices.dll A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.DirectoryServices.AccountManagement.dll
All my projects compile with .net4 and not .net4.5
during my debug now, I find that if I change the build platform target to AnyCPU, the code passed with no issue.
It seems like an OS bug! .Net 4 x86 not installed or something not right!, I tried to reinstall .Net4 but couldn't because it already installed, Iran .net cleanup tool as well.
Any Idea why this exception?