Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 奇怪错误:[ArgumentOutOfRangeException:';count';必须为非负_Asp.net_Nhibernate_Orm_Dependency Injection_Spring.net - Fatal编程技术网

Asp.net 奇怪错误:[ArgumentOutOfRangeException:';count';必须为非负

Asp.net 奇怪错误:[ArgumentOutOfRangeException:';count';必须为非负,asp.net,nhibernate,orm,dependency-injection,spring.net,Asp.net,Nhibernate,Orm,Dependency Injection,Spring.net,我有一个在ASP.NET 3.5、NHibernate 2.2和Sprint.NET中运行的站点,用于依赖项注入。在我们的测试服务器上,发生了一个相当奇怪的错误,而且几乎每次都有多个用户在线。问题发生后,每个用户和他们发出的每个请求都会显示此错误,直到您执行IISRESET。然后,它就消失了一切又好了 例外情况如下: 'count' must be non-negative. Parameter name: count Description: An unhandled exception o

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

例外情况如下:

'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));
            }        
        }
    }
}
您看到的异常必须由三个
新字符串(“”,nestingCount*INDENT)之一引发
调用。当提供的值为负值时,该特定的
字符串
构造函数调用将抛出。因为
缩进
是常量,
嵌套计数
在这种情况下必须有负值。
嵌套计数
是线程静态变量。线程静态变量总是用默认值初始化(在本例中为0)并且不受其他线程的影响。此外,
nestingCount
从未在该方法之外使用

由于
nestingCount
是线程静态的,并且仅在该方法中使用,因此很难想象
nestingCount
的场景会变为负值。可能在异步(ThreadAbort)的情况下例外,但即使这样我也很难想象。另一种选择是线程静态变量由其他人使用反射进行更改

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

解决方案:

我能想到的只有一件事,那就是以不记录调试信息的方式重新配置log4net构造函数可能永远不会被调用,这将隐藏问题。不太美观,但可能有效。这可能会起作用,因为
AbstractObjectFactory
使用
log
变量进行日志记录,该变量初始化如下:

this.log = LogManager.GetLogger(this.GetType());
您可以通过全局禁用在log4net中写入调试信息来实现这一点,或者——如果您认为这是一种过分的做法——将log4net配置为禁用类型
Spring.Objects.Factory.Support.DefaultListableObjectFactory的调试信息(实际导致异常的实例)


祝你好运。

在我的例子中,这个错误在性能测试过程中发生了一段时间。它开始时很好,过了一段时间这个错误就会弹出


原来是一个完全无关的[ThreadLocal]引起的我在代码中使用的变量。我用方法参数替换了它,现在它工作正常。

由于机密性,我无法发布所有代码,但所定位的对象是一个内部对象,具有ISession和ExceptionHandler作为构造函数参数。初始化该对象时会出现错误。禁用Spring.Obj的调试ects.Factory.Support.DefaultListableObjectFactory是一个可行的想法。我会尝试一下,看看这个错误不会再次发生。这个错误肯定很奇怪,但很有趣。希望根本原因只限于这个错误……谢谢Steven!如果有新的消息出现,我会更新帖子。@Mattias:我很好奇我的观察结果是正确的,如果禁用调试确实解决了您的问题。希望我能很快给您一个答案。这只发生在尚未上线的生产服务器上。因此,在下一次更新后,我们将看到。我将同时标记您的答案为已接受,因为它非常有洞察力。顺便说一句,到目前为止,很好。它已投入生产一段时间几个月过去了,错误已经不存在了。再次感谢!