Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.DirectoryServices.DirectorySearcher causing "Arithmetic operation resulted in overflow" errors

Tags:

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.

like image 911
Abhijeet Patel Avatar asked Apr 24 '12 02:04

Abhijeet Patel


1 Answers

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.

like image 65
Mothware Avatar answered Sep 27 '22 18:09

Mothware