【问题标题】:Intermittant Exception in System.DirectoryServicesSystem.DirectoryServices 中的间歇性异常
【发布时间】: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


【解决方案1】:

我知道你很久以前就问过这个问题,但我自己也遇到了这个问题,并通过我的构建配置管理器解决了这个问题,并确保所有项目都针对同一个 CPU - 我有 2 个构建到“任何 CPU”以及面向 x86 构建的 Windows 窗体测试应用程序。我将其更改为 Any CPU,问题就消失了。

here得到提示

【讨论】:

    【解决方案2】:

    最近我们将服务器升级到.NET 4.5 框架时发生了这种情况(我们遇到了FileNotFoundExceptionNotSupportedException)。我们的解决方案针对.NET 4,所以我相信当.NET 4.5 尝试运行.NET 4 应用程序并连接到Active Directory 时可能存在一些向后兼容性问题。

    将解决方案切换到目标 4.5 并重新发布到服务器似乎可以解决问题。

    下面是如何实现这一点。

    确保您的解决方案中的所有项目都针对4.5

    右击你的项目 -> Properties -> Application Tab

    同时确保 IIS 使用正确的框架版本(在发布时,它应该针对 4.0。):

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-17
      • 1970-01-01
      • 1970-01-01
      • 2012-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多