我希望Visual Studio在发生处理异常时中断(即我不只是想看到"第一次机会"消息,我想调试实际异常).
例如,我希望调试器在异常处中断:
try
{
System.IO.File.Delete(someFilename);
}
catch (Exception)
{
//we really don't care at runtime if the file couldn't be deleted
}
Run Code Online (Sandbox Code Playgroud)
我遇到了Visual Studio.NET的这些笔记:
1)在VS.NET中进入Debug菜单>>"Exceptions ...">>"Common Language Runtime Exceptions">>"System"并选择"System.NullReferenceException"
2)在该对话框的底部有一个"当抛出异常时:"组框,选择"进入调试器"
3)运行您的方案.抛出异常时,调试器将停止并通过一个对话框通知您,类似于:"抛出类型"System.NullReferenceException"的异常.[Break] [Continue]"
点击[休息].这将使您处于导致问题的代码行.
但它们不适用于Visual Studio 2005(" 调试"菜单上没有" 例外"选项).
有谁知道在Visual Studio中找到这个选项对话框中的" 当抛出异常时 "组框,并选择" 进入调试器 "?
更新:问题是我的调试菜单没有Exceptions项.我自定义菜单以手动添加它.
在Web应用程序中,我们希望显示属于特定组成员的用户的sam帐户列表.在许多情况下,组可以有500个或更多成员,我们需要页面响应.
一组约500名成员需要7-8秒才能获得该组所有成员的sam帐户列表.有更快的方法吗?我知道Active Directory管理控制台会在一秒钟内完成它.
我尝试过几种方法:
1)
PrincipalContext pcRoot = new PrincipalContext(ContextType.Domain)
GroupPrincipal grp = GroupPrincipal.FindByIdentity(pcRoot, "MyGroup");
List<string> lst = grp.Members.Select(g => g.SamAccountName).ToList();
Run Code Online (Sandbox Code Playgroud)
2)
PrincipalContext pcRoot = new PrincipalContext(ContextType.Domain)
GroupPrincipal grp = GroupPrincipal.FindByIdentity(pcRoot, "MyGroup");
PrincipalSearchResult<Principal> lstMembers = grp.GetMembers(true);
List<string> lst = new List<string>();
foreach (Principal member in lstMembers )
{
if (member.StructuralObjectClass.Equals("user"))
{
lst.Add(member .SamAccountName);
}
}
Run Code Online (Sandbox Code Playgroud)
3)
PrincipalContext pcRoot = new PrincipalContext(ContextType.Domain)
GroupPrincipal grp = GroupPrincipal.FindByIdentity(pcRoot, "MyGroup");
System.DirectoryServices.DirectoryEntry de = (System.DirectoryServices.DirectoryEntry)grp.GetUnderlyingObject();
List<string> lst = new List<string>();
foreach (string sDN in de.Properties["member"]) …Run Code Online (Sandbox Code Playgroud)