【问题标题】:Weird .Net 4, System.IO.FileNotFoundException when call UserPrincipal.FindByIdentity,奇怪的 .Net 4,调用 UserPrincipal.FindByIdentity 时出现 System.IO.FileNotFoundException,
【发布时间】:2016-04-25 06:52:47
【问题描述】:

在将我的系统从 win7 x64 升级到 win 10 x64 后,我开始遇到新的运行时 System.IO.FileNotFoundException 异常。

到目前为止,我有以下代码可以完美运行:

{
    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;                    

}

我总是使用平台目标:x86 构建项目,当我运行应用程序时,调用 UserPrincipal.FindByIdentity 时出现异常。

“System.IO.FileNotFoundException”类型的第一次机会异常 发生在 System.DirectoryServices.dll 的第一次机会异常 类型“System.IO.FileNotFoundException”发生在 System.DirectoryServices.AccountManagement.dll

我所有的项目都是用 .net4 而不是 .net4.5 编译的

在我现在的调试过程中,我发现如果我将构建平台目标更改为 AnyCPU,代码可以顺利通过。

这似乎是一个操作系统错误! .Net 4 x86 未安装或不正确!,我尝试重新安装 .Net4 但无法安装,因为它已经安装,伊朗 .net 清理工具也是如此。

知道为什么会出现这个异常吗?

【问题讨论】:

标签: c# active-directory windows-10 runtimeexception


【解决方案1】:

它说缺少程序集 System.DirectoryServices.dll。您是否有机会验证 dll 是否存在于您当前的解决方案中。如果没有尝试下载 nuget,构建并查看。我遇到了类似的问题,下载 System.DirectoryServices dll 后,它在 vs 2017 和 .net core 2.1 中得到了解决

【讨论】:

    猜你喜欢
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多