问题
I'm getting the following intermittent errors related to querying AD using
DirectorySearcher.FindOne()
or FindAll()
.
System.OverflowException: Arithmetic operation resulted in an overflow.
at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.GetCurrentResult()
at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.get_Current()
at System.DirectoryServices.SearchResultCollection.ResultsEnumerator.System.Collections.IEnumerator.get_Current()
This is happening in a web app and seems to happen after the app has been running for several hours.
This is a documented issue on Microsoft Connect but it looks like it has been marked as "not reproducible" and closed.
The only fix that I found here is to recycle the app pool periodically which is a rather harsh workaround and not viable when your users are in the middle of working.
Has anyone experienced this and if so how was this resolved?
I have tried to use caching but this just delays the inevitable until you hit a certain threshold in terms of the number of AD calls since people have reported that each time the API call is made it leaks memory.
Any help would be much appreciated.
回答1:
Build an AD API and run it in it's own app pool. The recycle that every few hours. All the API will handle is calls to AD. looks like you already have the code, just need to move to API. I have found a AD API to be very useful for lots of other projects as well and keep going back to it as reference point.
来源:https://stackoverflow.com/questions/10291009/system-directoryservices-directorysearcher-causing-arithmetic-operation-resulte