Interrupt Exception in System.DirectoryServices

I have a strange System.DirectoryServices problem that appears periodically.

The below exception is periodically thrown in the code below

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; } } 

Stacktrace exception in System.Reflection.RuntimeAssembly._nLoad (AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark & ​​stackMark, Boolean throwOnFileNotFound, BooleanEmeLiefLementLiefNementLiefNeferencePreferenceNextRepreference , StackCrawlMark & ​​stackMark) in System.DirectoryServices.AccountManagement.UnsafeNativeMethods.IADsPathname.Retrieve (Int32 lnFormatType) in System.DirectoryServices.AccountManagement.ADStoreCtx.LoadDomainInfo () in System.DirectMentoryStoreContainmentStoreContainmentStoreContainmentStoreContainmentStoreContainmentStoreContainmentStoreContainmentMonitorContainmentMonitorInstore.ContentManager AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ (Principal p) in System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper ()

Something very strange is Exception.Message, which: Failed to load the file or assembly "MyCustomAssembly.XmlSerializers" or one of its dependencies. The system cannot find the specified file.

The funny thing is that MyCustomAssembly is not even mentioned in this assembly.

I think Exception.Message does not match Debug information, and the actual Stacktrace is more or less the correct Exception.

Any idea why this is happening?

+4
source share
2 answers

I know that you asked this a long time ago, but I had the problem itself, and I solved it by going through my build configuration manager and making sure that all projects are aimed at the same processor - I had 2 buildings for "Any CPU" , and a Windows Forms test application built in the x86 direction. I changed this to any CPU and the problem disappeared.

Got feedback from here

+4
source

This happened recently when we upgraded the server to the .NET 4.5 framework (we met FileNotFoundException and NotSupportedException ). Our solution was designed for .NET 4 , so I think that may be a problem of backward compatibility when .NET 4.5 is trying to run the application .NET 4 and connect to Active Directory .

Switching the solution to target 4.5 and republishing to the server seemed to do the trick.

The following describes how to do this.

Make sure all projects in your solution are targeting 4.5 :

Right click on your project -> Properties Application Tab

enter image description here

Also make sure IIS uses the correct version of the frame (at the time of publication, it should target 4.0.):

0
source

Source: https://habr.com/ru/post/1397989/


All Articles