I have a strange System.DirectoryServices Issue which pops up intermittantly.
The exception below gets thrown periodically in the below code
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;
}
}
Exception Stacktrace at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.LoadWithPartialNameInternal(AssemblyName an, Evidence securityEvidence, StackCrawlMark& stackMark) at System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADsPathname.Retrieve(Int32 lnFormatType) at System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo() at System.DirectoryServices.AccountManagement.ADStoreCtx.get_DnsDomainName() at System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(Principal p) at System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper()
Something also very strange is the Exception.Message which is : Could not load file or assembly 'MyCustomAssembly.XmlSerializers' or one of its dependencies. The system cannot find the file specified
The funny thing is that MyCustomAssembly is not even referenced in this assembly.
I think the Exception.Message is mismatching the Debug info and the actual Stacktrace is more or less the correct Exception.
Any idea why this is happening?