【发布时间】: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 清理工具也是如此。
知道为什么会出现这个异常吗?
【问题讨论】:
-
@gpro 在发布问题之前,我尝试添加缺少的注册表(“RegisteredOwner 和 RegisteredOrganization”),但没有成功! ,你也可以在第二个帖子中看到我的评论!
标签: c# active-directory windows-10 runtimeexception