2010-11-22 5 views
4

ASP.NET 3.5, NHibernate 2.2 및 Sprint .NET에서 종속 삽입을 실행하는 사이트가 있습니다. 우리의 테스트 서버에서 오히려 이상한 오류가 발생하고 거의 언제나 온라인에 여러 명의 사용자가 있습니다. 문제가 발생한 후에는 IISRESET을 수행 할 때까지 모든 사용자와 모든 요청에 ​​대해이 오류가 표시됩니다. 그럼 다시 다 괜찮아. 데이터베이스 컬럼이 하나 개 이상의 속성에 매핑 할 때 나는이 오류가 발생할 본이상한 오류 : [ArgumentOutOfRangeException : 'count'가 음수가 아니어야합니다.

'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 

답변

3

이것은 실제로 매우 심오한 오류입니다. 당신의 소스에서 볼 때 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) 호출 중 하나에 의해 발생해야보고있는 예외입니다. 그 특정 값 생성자 호출은 제공된 값이 음수 일 때 throw합니다. INDENT은 const이기 때문에 nestingCount은이 경우 음수 값을 가져야합니다. nestingCount은 thread-static 변수입니다. 스레드 정적 변수는 항상 기본값 (이 경우 0)으로 초기화되며 다른 스레드의 영향을받을 수 없습니다. 더우기 nestingCount은이 방법 밖에서 사용되지 않습니다.

nestingCount은 스레드 고정적이며 그 방법에서만 사용되기 때문에 nestingCount이 부정적인 결과를 가져올 수 있다고 상상하기가 어렵습니다. 아마 비동기 (ThreadAbort) 예외의 경우에는, 그러나 이것조차도 상상하기 힘들다. 다른 옵션은 thread-static 변수가 리플렉션을 사용하는 다른 누군가에 의해 변경된다는 것입니다.

하지만 큰 문제는 어떻게 해결할 수 있습니까?

솔루션 :

이 내가 생각할 수있는 단 한 가지이고 그 정보가 기록되지 않습니다 디버깅 방식으로 재구성 log4net입니다. 디버그 정보를 허용하지 않으면 string(char, int) 생성자가 다시 호출되지 않으므로 문제가 숨겨집니다. 그리 예쁜 것은 아니지만 효과적 일 수 있습니다. AbstractObjectFactory 로그가 다음과 같이 초기화됩니다 log 변수를 사용하기 때문에이 작동하지 않을 수 있습니다 : 당신이 생각 - 언제

this.log = LogManager.GetLogger(this.GetType()); 

당신은 세계적으로 log4net에서 디버그 정보의 기록을 해제하여이 작업을 수행 할 수 있습니다를, 또는이에 의해 overkill-입니다 log4net을 구성하여 Spring.Objects.Factory.Support.DefaultListableObjectFactory 유형의 디버그 정보를 비활성화합니다 (실제로 예외가 발생하는 인스턴스).

행운을 빈다.

+0

Spring.Objects.Factory.Support.DefaultListableObjectFactory에 대한 디버그를 사용하지 않으면 작동하는 아이디어입니다. 나는 이것을 시도 할 것이고 오류가 다시 발생하지 않을 것을 볼 것이다. 오류는 확실히 이상하지만 꽤 흥미 롭습니다. 바라건대 기본 원인은이 오류에만 국한 될 것입니다 ... 감사합니다 스티븐! 새로운 것이 있으면 엽서를 업데이트 해 두겠습니다. – Mattias

+0

@Mattias : 내 관찰 결과가 정확하고 디버그를 사용 중지해도 문제가 해결되면 매우 궁금합니다. – Steven

+0

잘하면 나는 곧 당신에게 대답을 줄 수 있습니다. 이것은 아직 살아 있지 않은 프로덕션 서버에서만 발생합니다. 그래서 다음번 업데이트 후에 보게 될 것입니다. – Mattias

0

:

다음은 예외입니다. 일반적인 경우는 외래 키 열이 속성과 컬렉션으로 매핑되는 경우입니다. 구성 파일에있는 두 번째 또는 세 번째 눈 쌍이이를 확인하는 데 도움이됩니다.

이것은 모든 사용자에 대해 발생하는 하나의 트위스트입니다. 응용 프로그램 상태에 저장된 영구 객체가 있습니까?

+0

기밀로 인해 모든 코드를 게시 할 수는 없지만 생성자 인수로 ISession 및 ExceptionHandler가있는 내부 개체입니다. 해당 개체를 초기화 할 때 오류가 나타납니다. – Mattias

0

필자의 경우 성능 테스트 중 잠시 후에이 오류가 발생했습니다. 그것은 잘 시작하고 언젠가는이 오류가 팝업 후.

내 코드에서 사용 된 전혀 관련이없는 [ThreadLocal] 변수로 인해 발생했습니다. 메소드 매개 변수로 바꿔서 이제는 잘 동작합니다.