Castle Trunk 및 Nhibernate 2.1.0.4000으로 업그레이드 한 후 통합 테스트 충돌 테스트 드라이브.

StackOverflow https://stackoverflow.com/questions/1832394

문제

나는 오래된 모노레일/activerecord가 있습니다.

최근에 나는 응용 프로그램을 Castle Trunk & Nhibernate 2.1.0.4000 GA로 업그레이드하기로 결정했으며 이제 실행 테스트와 관련하여 몇 가지 문제가 있습니다.

먼저 - testdriven.net을 사용하여 데이터베이스에 대해 작동하는 통합 테스트를 실행할 때 TestDriven.net이 모두 충돌하거나 모든 테스트가 완료 한 다음 TestDriven.net이 중단됩니다. 업그레이드 전에는 결코 일어나지 않았습니다.

TestDriven.net이 충돌하면 이벤트 로그에 기록되는 내용은 다음과 같습니다.

결함 버킷 1467169527, 유형 1 이벤트 이름 : AppCrash 응답 : 사용 가능한 CAB ID : 0

문제 시그니처 : P1 : ProcessInvocation86.exe P2 : 2.22.2468.0 P3 : 4A26845C P4 : Kernelbase.dll P5 : 6.1.7600.16385 P6 : 4A5BDBDF P7 : E053534F P8 : 0000B727 P9 : P10 :

두 번째 - 프록시 클래스가 () 'D를 마무리 할 때 예외가 기록되고 있습니다 (아래와 같이). 일단 두 번 기록되면 TestDriven.net이 충돌 할 때입니다.

예외를위한 스택 추적은 다음과 같습니다.

NHibernate.LazyInitializationException:     
Initializing[MyApp.Core.Models.TestExecutionPackage#15d9eb96-faf0-4b4b-9c5c-9cd400065430]-Could not initialize proxy - no Session.
  at NHibernate.Proxy.AbstractLazyInitializer.Initialize()
  at NHibernate.Proxy.AbstractLazyInitializer.GetImplementation()
  at NHibernate.ByteCode.Castle.LazyInitializer.Intercept(IInvocation invocation)
  at Castle.DynamicProxy.AbstractInvocation.Proceed()
  at Castle.Proxies.TestExecutionPackageProxy.Finalize()

동일한 동작도 CI 서버에서 MSBuild 충돌합니다.

정말 이상한 점은 이론적으로 마무리 ()에 던져진 예외적으로 MSDN 문서에 따라 삼켜야한다는 것입니다.

http://msdn.microsoft.com/en-us/library/system.object.finalize(vs.71).aspx

만약에 마무리하십시오 또는 재정의 마무리하십시오 예외를 던지면 런타임은 예외를 무시하고 마무리하십시오 방법, 최종화 프로세스를 계속합니다.

누구도 생각해?

도움이 되었습니까?

해결책

이 문제의 맨 아래에 결코 얻지 못했지만, 아래와 같이 호출시 최종 메소드를 확인하는 내 자신의 Lazyinitializer 구현을 만들어 다소 기초적인 작업을 구현하게되었습니다.

/// <summary>
/// Invoke the actual Property/Method using the Proxy or instantiate the actual
/// object and use it when the Proxy can't handle the method. 
/// </summary>
/// <param name="invocation">The <see cref="IInvocation"/> from the generated Castle.DynamicProxy.</param>
public virtual void Intercept(IInvocation invocation)
{
  try
  {
    if (invocation.Method.Name == "Finalize")
    {
      return;
    }
    if (_constructed)
    {
      // let the generic LazyInitializer figure out if this can be handled
      // with the proxy or if the real class needs to be initialized
      invocation.ReturnValue = base.Invoke(invocation.Method, invocation.Arguments, invocation.Proxy);

      // the base LazyInitializer could not handle it so we need to Invoke
      // the method/property against the real class
      if (invocation.ReturnValue == InvokeImplementation)
      {
        invocation.ReturnValue = invocation.Method.Invoke(GetImplementation(), invocation.Arguments);
        return;
      }
      else
      {
        return;
      }
    }
    else
    {
      // TODO: Find out equivalent to CGLIB's 'method.invokeSuper'.
      return;
    }
  }
  catch (TargetInvocationException tie)
  {
    // Propagate the inner exception so that the proxy throws the same exception as
    // the real object would 
    Exception_InternalPreserveStackTrace.Invoke(tie.InnerException, new Object[] { });
    throw tie.InnerException;
  }
}

다른 팁

i가 2.1.2 버전의 nhibernate로 마이그레이션했을 때도 같은 문제가있었습니다. 나는 Linfu Proxy를 위해 Castle을 바꾸었고 모든 것이 나에게 잘 작동했습니다. 도움이 되었기를 바랍니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top