1

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?

Joseph
  • 1,716
  • 3
  • 24
  • 42
  • Check these: http://stackoverflow.com/questions/34971400/c-sharp-cannot-use-principalcontextcontexttype-machine-on-windows-10-the-sy/34988434 http://stackoverflow.com/questions/34971400/c-sharp-cannot-use-principalcontextcontexttype-machine-on-windows-10-the-sy http://stackoverflow.com/questions/33717673/system-directoryservices-accountmanagement-principalcontext-broken-after-windows – gpro Apr 25 '16 at 08:50
  • @gpro before post the question, I tried and add the missing registry ("RegisteredOwner and RegisteredOrganization") with no luck! , also you can see my comment in the 2nd post! – Joseph Apr 25 '16 at 09:27

1 Answers1

0

It says the assembly System.DirectoryServices.dll missing. Did you get a chance to verify if the dll is present in your current solution. If not try to download for nuget, build and see. I faced a similar issue and it got resolved with vs 2017 and .net core 2.1 after downloading the System.DirectoryServices dll