System.DirectoryServices.DirectorySearcher导致"算术运算导致溢出"错误

Abh*_*tel 23 .net directoryservices memory-leaks active-directory

我收到以下与使用DirectorySearcher.FindOne()或查询AD相关的间歇性错误 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()
Run Code Online (Sandbox Code Playgroud)

这是在一个Web应用程序中发生的,似乎是在应用程序运行了几个小时后发生的.

这是Microsoft Connect上的文档问题,但看起来它已标记为"不可重现"并已关闭.

我在这里找到的唯一解决方案是定期回收应用程序池,这是一个相当苛刻的解决方法,当用户处于工作中时不可行.

有没有人经历过这个,如果是这样,这是如何解决的?

我曾尝试使用缓存,但这只会延迟不可避免的事情,直到你达到AD调用次数的某个阈值,因为人们已经报告每次调用API时它会泄漏内存.

任何帮助将非常感激.

Mot*_*are 1

构建 AD API 并在其自己的应用程序池中运行它。每隔几个小时回收一次。所有 API 将处理对 AD 的调用。看起来您已经有了代码,只需要转到 API 即可。我发现 AD API 对于许多其他项目也非常有用,并不断将其作为参考点。