【问题标题】:NUnit crashing with NHibernateNUnit 与 NHibernate 崩溃
【发布时间】:2011-11-07 07:22:31
【问题描述】:

我正在使用 NUnit 运行一些 NHibernate 测试,但 NUnit 测试代理正在崩溃。我知道没什么可做的,但显然 NUnit 本身不应该崩溃。

这是堆栈跟踪...我不明白它试图连接到哪个服务器或为什么,或者为什么 NUnit 本身崩溃。我猜这是我的 .hbm 文件的问题,因为 NUnit 在我的架构创建测试中崩溃,它只包含以下内容:

var configuration = new Configuration();
configuration.Configure();
configuration.AddAssembly(typeof(AnEntityTypeInMyDomain).Assembly);
new SchemaExport(configuration).Execute(false, true, false);

抱歉,我真的没有更多信息 - 有什么想法吗?

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:30168

Server stack trace: 
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
   at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at NUnit.Core.TestRunner.get_Running()
   at NUnit.Core.ProxyTestRunner.get_Running()
   at NUnit.Util.TestLoader.get_Running()
   at NUnit.Gui.NUnitForm.get_IsTestRunning()
   at NUnit.Gui.NUnitForm.CancelRun()
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5446 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
nunit
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.5.10.11092
    CodeBase: file:///C:/Program%20Files%20(x86)/NUnit%202.5.10/bin/net-2.0/nunit.exe
----------------------------------------
nunit-gui-runner
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.5.10.11092
    CodeBase: file:///C:/Program%20Files%20(x86)/NUnit%202.5.10/bin/net-2.0/lib/nunit-gui-runner.DLL
----------------------------------------
nunit.core
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.5.10.11092
    CodeBase: file:///C:/Program%20Files%20(x86)/NUnit%202.5.10/bin/net-2.0/lib/nunit.core.DLL
----------------------------------------
nunit.util
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.5.10.11092
    CodeBase: file:///C:/Program%20Files%20(x86)/NUnit%202.5.10/bin/net-2.0/lib/nunit.util.DLL
----------------------------------------
nunit.core.interfaces
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.5.10.11092
    CodeBase: file:///C:/Program%20Files%20(x86)/NUnit%202.5.10/bin/net-2.0/lib/nunit.core.interfaces.DLL
----------------------------------------
nunit.uikit
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.5.10.11092
    CodeBase: file:///C:/Program%20Files%20(x86)/NUnit%202.5.10/bin/net-2.0/lib/nunit.uikit.DLL
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5447 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5446 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
nunit.uiexception
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.5.10.11092
    CodeBase: file:///C:/Program%20Files%20(x86)/NUnit%202.5.10/bin/net-2.0/lib/nunit.uiexception.DLL
----------------------------------------
Accessibility
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.4927 (NetFXspW7.050727-4900)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
System.Web
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.5420 (Win7SP1.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_64/System.Web/2.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
mm7fptoa
    Assembly Version: 2.5.10.11092
    Win32 Version: 2.0.50727.5447 (Win7SP1GDR.050727-5400)
    CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

【问题讨论】:

    标签: nhibernate nunit


    【解决方案1】:

    显然这是罪魁祸首:

    configuration.AddAssembly(typeof(AnEntityTypeInMyDomain).Assembly);
    

    执行此操作的代码已经在包含AnEntityTypeInMyDomain 的程序集中。 AddAssembly 添加在给定程序集中以 .hbm.xml 结尾的所有嵌入资源。所以那些 .hbm.xml 文件被添加了两次。

    我猜这会以某种方式导致堆栈溢出,从而导致我进入堆栈溢出(呵呵),因为这可以解释为什么 NUnit 崩溃了,因为堆栈溢出没有转换为 StackOverflowException

    我有点惊讶它没有检查是否已经添加了程序集...

    让我修改一下:问题是堆栈溢出导致 NUnit 测试代理崩溃,导致 NUnit 测试运行器失去与代理的连接(解释了 SocketException)。

    现在,堆栈溢出的原因。在我的一些模型类的构造函数中,我分配了一个存储库类来获取关联实体的 ID。现在,存储库类打开了一个 NHibernate 会话;构建会话工厂会分配模型类的实例...您可以看到这是怎么回事。

    所以我只是使用不同的方法来关联另一个实体。

    【讨论】:

      【解决方案2】:

      看起来它尝试使用远程处理访问某个远程对象,但失败了,因为远程对象(在本例中为本地对象:127.0.0.1:30168)尚未准备好与您的测试对话。

      这是一个重复的问题(虽然没有回答): Nhibernate Error: BuidSessionFactory() Deadlock / Dropping Connection

      【讨论】:

      • 即使我的测试正在与某些东西对话(除了 SQL Server,它不是),它也不应该使 NUnit 崩溃。问题是,它直到最近都运行良好,我还没有添加任何与网络相关的内容。
      • 是的,发生了一些奇怪的事情。我发现有六个人遇到了同样的问题,但到目前为止还没有解决方案。
      猜你喜欢
      • 2012-08-24
      • 1970-01-01
      • 2011-01-18
      • 1970-01-01
      • 2018-02-21
      • 2011-08-19
      • 2010-09-13
      • 2018-07-14
      • 2020-01-26
      相关资源
      最近更新 更多