.net System.DirectoryServices中的间歇性异常
我有一个奇怪的System.DirectoryServices问题,它会间歇性出现 下面的异常会在下面的代码中定期抛出.net System.DirectoryServices中的间歇性异常,.net,exception-handling,active-directory,directoryservices,.net,Exception Handling,Active Directory,Directoryservices,我有一个奇怪的System.DirectoryServices问题,它会间歇性出现 下面的异常会在下面的代码中定期抛出 private PrincipalSearchResult<Principal> GetAuthorizationGroups(UserPrincipal userPrincipal, int tries) { try { //Exception is thrown on this line b
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;
}
}
private PrincipalSearchResult GetAuthorizationGroups(UserPrincipal UserPrincipal,int)
{
尝试
{
//在下面的这一行抛出异常
返回userPrincipal.GetAuthorizationGroups();
}
捕获(AppDomainUnloadedException ex)
{
如果(尝试次数>5)
{
投掷;
}
尝试次数+=1;
睡眠(5000);
返回GetAuthorizationGroups(userPrincipal,tries);
}
捕获(例外情况除外)
{
投掷;
}
}
System.Reflection.RuntimeAssembly处出现异常Stacktrace.\u System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal处的加载(AssemblyName文件名、字符串代码库、证据assemblySecurity、RuntimeAssembly位置提示、StackScrawMark和stackMark、Boolean throwOnFileNotFound、Boolean ForInterlection、Boolean suppressSecurityChecks)在System.DirectoryServices.AccountManagement.AdStoreCx.get\DnsDomainName()中的System.DirectoryServices.AccountManagement.AdStoreCx.LoadDomainInfo()处的System.DirectoryServices.AccountManagement.UnsafentiveMethods.IADsPathname.Retrieve(Int32 LnformationType)处的(AssemblyName an,证据安全性证据,StackScrawlMark和stackMark)位于System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(主体p)的System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper()
还有一个非常奇怪的例外。消息是:
无法加载文件或程序集“MyCustomAssembly.XmlSerializers”或其依赖项之一。系统找不到指定的文件
有趣的是,MyCustomAssembly甚至没有在这个程序集中引用
我认为Exception.Message与调试信息不匹配,实际的Stacktrace或多或少是正确的异常
知道为什么会发生这种情况吗?我知道你很久以前问过这个问题,但我自己也遇到了这个问题,通过查看构建配置管理器并确保所有项目都针对同一个CPU解决了这个问题-我有2个构建到“任意CPU”和一个面向x86的Windows窗体测试应用程序。我将其更改为任何CPU,问题就消失了
从获得提示最近我们将服务器升级到
.NET 4.5
框架时遇到了这种情况(我们遇到了FileNotFoundException
和NotSupportedException
)。我们的解决方案的目标是.NET 4
,因此我认为当.NET 4.5
尝试运行.NET 4
应用程序并连接到Active Directory
时,可能存在向后兼容性问题
将解决方案切换到target4.5
,并重新发布到服务器上似乎就可以做到这一点
下面是如何实现这一点
确保解决方案中的所有项目都以4.5
为目标:
右键单击项目->属性
->应用程序选项卡
还要确保IIS
使用的是正确的框架版本(发布时,应以4.0为目标):
这是正常现象。调试+异常,取消选中CLR异常的抛出框。可能重复您是说我应该捕获并忽略该异常吗?调试中没有发生上述异常。我没有调试应用程序。此异常在运行时引发。Web应用程序发布到IIS。此问题导致我们的自动测试失败ted测试系统!在我的开发人员机器上运行测试时不会发生这种情况。触发异常的代码正好位于ActiveDirectory主体处理代码中。我们无法在调试菜单中取消选中任何异常,因为它不会发生在我的调试器中。