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

1

23

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.

Guenzi answered 24/4, 2012 at 2:30 Comment(5)
I have exactly the same issue, and have come to the same conclusion that Microsoft has yet to acknowledge this and provide a fix. The only other tidbit I can provide is the suggestion to look into your password age policy as stated here: social.technet.microsoft.com/Forums/en-US/scoscip/thread/…Tercentenary
The real issue in my case was not related to AD as much as an issue in the MS enterprise library based data access code that was causing memory leaks which in turn was causing issues with memory allocation in AD lookup related code.Guenzi
That is interesting, as we don't use the enterprise library for anything. I guess it is possible that we have another memory leak and AD just needs that much memory? Can you tell me if you were using IIS in 64 or 32-bit mode?Tercentenary
I believe it was in 32 bit mode. I bet you have a memory leak some place else. Have you tried using SOS or any of the other debugging tools? This SO post is useful as well-#5275066Guenzi
Just a thought: are you disposing each SearchResultCollection you instantiate? MSDN states that a memory leak can occur if you fail to do so - see the Remarks section of msdn.microsoft.com/en-us/library/…Livelong
A
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.

Antilogy answered 16/7, 2015 at 18:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.