【发布时间】:2012-02-23 09:33:14
【问题描述】:
我有一个奇怪的 System.DirectoryServices 问题,它间歇性地弹出。
下面的异常会在下面的代码中定期抛出
private PrincipalSearchResult<Principal> GetAuthorizationGroups(UserPrincipal userPrincipal, int tries)
{
try
{
//Exception is thrown on this line below
return userPrincipal.GetAuthorizationGroups();
}
catch (AppDomainUnloadedException ex)
{
if (tries > 5)
{
throw;
}
tries += 1;
Thread.Sleep(5000);
return GetAuthorizationGroups(userPrincipal, tries);
}
catch (Exception ex)
{
throw;
}
}
System.Reflection.RuntimeAssembly._nLoad 的异常堆栈跟踪(AssemblyName 文件名,字符串代码库,证据 assemblySecurity,RuntimeAssembly locationHint,StackCrawlMark 和 stackMark,布尔 throwOnFileNotFound,布尔 forIntrospection,布尔suppressSecurityChecks)在 System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an,在 System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo() 在 System.DirectoryServices.AccountManagement.ADStoreCtx.get_DnsDomainName() 在 System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo() 在 System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADsPathname.Retrieve(Int32 lnFormatType) 的证据 securityEvidence、StackCrawlMark 和 stackMark) .AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(Principal p) at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper()
还有一点很奇怪的是 Exception.Message,它是: 无法加载文件或程序集“MyCustomAssembly.XmlSerializers”或其依赖项之一。系统找不到指定的文件
有趣的是,MyCustomAssembly 甚至没有在这个程序集中被引用。
我认为 Exception.Message 与 Debug 信息不匹配,而实际的 Stacktrace 或多或少是正确的 Exception。
知道为什么会这样吗?
【问题讨论】:
-
这是正常的。 Debug + Exceptions,取消选中抛出的 CLR 异常框。
-
你是说我应该抓住并忽略那个异常?
-
调试中没有发生上述异常。我没有调试应用程序。此异常在运行时引发。 Web 应用已发布到 IIS。
-
这个问题会导致我们的自动化测试系统中的测试失败!当我在我的开发人员机器上运行测试时,它不会发生。触发异常的代码恰好在 ActiveDirectory 主体处理代码中。在 Debug 菜单中取消勾选任何 Exception 对我们来说不是一个解决方案,因为它不会在我的调试器中发生。
标签: .net exception-handling active-directory directoryservices