gpt4 book ai didi

asp.net - 奇怪的错误 : [ArgumentOutOfRangeException: 'count' must be non-negative

转载 作者:行者123 更新时间:2023-12-01 02:52:59 25 4
gpt4 key购买 nike

我有一个在 ASP.NET 3.5、NHibernate 2.2 和 Sprint .NET 中运行的站点,用于依赖注入(inject)。在我们的测试服务器上发生了一个相当奇怪的错误,而且几乎每次都有多个用户在线。问题发生后,每个用户和他们提出的每个请求都会显示此错误 - 直到您执行 IISRESET。然后一切都好了。

这是一个异常(exception):

'count' must be non-negative.
Parameter name: count
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: 'count' must be non-negative.
Parameter name: count

Source Error:
[No relevant source lines]

Source File: c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\4bf9aa39\6dcf5fc6\App_Web_z9ifuy6t.6.cs Line: 0

Stack Trace:
[ArgumentOutOfRangeException: 'count' must be non-negative.
Parameter name: count]
System.String.CtorCharCount(Char c, Int32 count) +10082288
Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure) +3612
Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name) +75
Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) +365
Spring.Context.Support.AbstractApplicationContext.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects) +136
Spring.Context.Support.AbstractApplicationContext.GetObjectsOfType(Type type) +66


[ActivationException: Activation error occured while trying to get instance of type InfoTextService, key ""]
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:57
Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance() in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:90
OurProjectsNamespace.Infrastructure.ObjectLocator.LocateService() +86

最佳答案

这确实是一个非常奇怪的错误。当您查看 AbstractObjectFactory.GetObjectInternal 的来源时您将看到以下结构:

[ThreadStatic]
private int nestingCount;

protected object GetObjectInternal(...)
{
const int INDENT = 3;
bool hasErrors = false;
try
{
nestingCount++;

if (log.IsDebugEnabled)
{
log.Debug("msg" +
new String(' ', nestingCount * INDENT));
}

// More code: Calls self recursively.
}
catch
{
nestingCount--;
hasErrors = true;

if (log.IsErrorEnabled)
{
log.Error("msg" +
new String(' ', nestingCount * INDENT));
}
}
finally
{
if (!hasErrors)
{
nestingCount--;
if (log.IsDebugEnabled)
{
log.Debug("msg" +
new String(' ', nestingCount * INDENT));
}
}
}
}

您看到的异常必须由三个 new String(' ', nestingCount * INDENT) 之一引发。来电。那个特别的 string当提供的值为负时,构造函数调用抛出。因为 INDENT是一个常量, nestingCount在这种情况下必须有一个负值。 nestingCount是一个线程静态变量。线程静态变量始终使用其默认值(在本例中为 0)初始化,并且不受其他线程的影响。此外, nestingCount从未在此方法之外使用。

因为 nestingCount是线程静态的并且仅用于该方法,很难想象一个场景是 nestingCount可以得到负面的。也许在异步(ThreadAbort)异常的情况下,但即使这样我也很难想象。其他选择是线程静态变量由其他人使用反射更改。

但最大的问题是:如何解决这个问题?

解决方案:

我只能想到一件事,那就是以不记录调试信息的方式重新配置 log4net。当禁止调试信息时, string(char, int)构造函数可能永远不会再次被调用,这将隐藏问题。不是很漂亮,但可能有效。这可能有效,因为 AbstractObjectFactory使用 log 的日志初始化如下的变量:
this.log = LogManager.GetLogger(this.GetType());

您可以通过在 log4net 中全局禁用调试信息的写入来做到这一点,或者 – 当您认为这太过分时 – 通过配置 log4net 来禁用类型 Spring.Objects.Factory.Support.DefaultListableObjectFactory 的调试信息(实际上是导致异常的实例)。

祝你好运。

关于asp.net - 奇怪的错误 : [ArgumentOutOfRangeException: 'count' must be non-negative,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4246747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com