Good afternoon,
I have been stuck on this issue for a number of days now and I don't feel my understanding of Nhibernate / SQL Server is of enough so that I might figure it out.
The issue is that any unit test that involves making a call to:
Nhibernate.Cfg.Configuaration.BuildSessionFactory();
Just becomes stuck in a running state, I am forced to press 'Stop' in order to get NUnit to respond. At which point an error dialogue appears with the following information:
"No connection could be made because the target machine actively refused it"
With the "exception text" being;
System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:51293
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)
My NHibernate is configured like so;
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=MachineName\SQLEXPRESS;database=TestingDB;Integrated Security=true;</property>
<property name ="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, Nhibernate.ByteCode.LinFu</property>
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>
and with the TestFixtureSetup calling the following:
_configuration.Configure();
_configuration.AddAssembly(typeof(MyClass).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
The test simply hangs on the final line. To try and understand what is going wrong, I enabled log4net which gave the following output when running a test.
[TestRunnerThread] INFO NHibernate.Cfg.Environment - NHibernate 2.1.2.4000 (2.1.2.4000)
[TestRunnerThread] INFO NHibernate.Cfg.Environment - hibernate-configuration section not found in application configuration file
[TestRunnerThread] INFO NHibernate.Cfg.Environment - Bytecode provider name : lcg
[TestRunnerThread] INFO NHibernate.Cfg.Environment - Using reflection optimizer
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - connection.provider=NHibernate.Connection.DriverConnectionProvider
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - dialect=NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - connection.driver_class=NHibernate.Driver.SqlClientDriver
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - connection.connection_string=Server=MachineName\SQLEXPRESS;database=MySolution_Testing;Integrated Security=true;
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - proxyfactory.factory_class=NHibernate.ByteCode.LinFu.ProxyFactoryFactory, Nhibernate.ByteCode.LinFu
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - show_sql=true
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - properties: System.Collections.Generic.Dictionary`2[System.String,System.String]
[TestRunnerThread] INFO NHibernate.Cfg.Configuration - Mapping resource: MySolution.Models.Mappings.MenuItem.hbm.xml
[TestRunnerThread] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: MySolution.Models.MenuItem -> MenuItems
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ID -> MenuItemID, type: Int32
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Name -> MenuItemName, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ControllerName -> MenuItemController, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ActionName -> MenuItemAction, type: String
[TestRunnerThread] INFO NHibernate.Cfg.Configuration - Mapping resource: MySolution.Models.Mappings.Perspective.hbm.xml
[TestRunnerThread] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: MySolution.Models.UserPerspective -> Perspectives
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ID -> PerspectiveID, type: Int32
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Name -> PerspectiveName, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Description -> PerspectiveDescription, type: String
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Password -> PerspectivePassword, type: String
[TestRunnerThread] INFO NHibernate.Cfg.Configuration - Mapping resource: MySolution.Models.Mappings.ViewGroup.hbm.xml
[TestRunnerThread] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: MySolution.Models.ViewGroup -> ViewGroups
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: ID -> ViewGroupID, type: Int32
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: Perspective -> Link_PerspectiveID, type: MySolution.Models.UserPerspective
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped property: MenuItems, type: Iesi.Collections.Generic.ISet`1[[MySolution.Models.MenuItem, MySolution.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]](MySolution.Models.ViewGroup.MenuItems)
[TestRunnerThread] INFO NHibernate.Cfg.Configuration - checking mappings queue
[TestRunnerThread] INFO NHibernate.Cfg.Configuration - processing one-to-many association mappings
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Second pass for collection: MySolution.Models.ViewGroup.MenuItems
[TestRunnerThread] INFO NHibernate.Cfg.XmlHbmBinding.Binder - mapping collection: MySolution.Models.ViewGroup.MenuItems -> MenuItems
[TestRunnerThread] DEBUG NHibernate.Cfg.XmlHbmBinding.Binder - Mapped collection key: MenuItemID, one-to-many: MySolution.Models.MenuItem
[TestRunnerThread] INFO NHibernate.Cfg.Configu开发者_运维百科ration - processing one-to-one association property references
[TestRunnerThread] INFO NHibernate.Cfg.Configuration - processing foreign key constraints
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - resolving reference to class: MySolution.Models.ViewGroup
[TestRunnerThread] DEBUG NHibernate.Cfg.Configuration - resolving reference to class: MySolution.Models.UserPerspective
[TestRunnerThread] INFO NHibernate.Cfg.Configuration - processing filters (second pass)
[TestRunnerThread] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect
[TestRunnerThread] INFO NHibernate.Exceptions.SQLExceptionConverterFactory - Using dialect defined converter
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Generate SQL with comments: disabled
[TestRunnerThread] INFO NHibernate.Connection.ConnectionProviderFactory - Initializing connection provider: NHibernate.Connection.DriverConnectionProvider
[TestRunnerThread] INFO NHibernate.Connection.ConnectionProvider - Configuring ConnectionProvider
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Transaction factory: NHibernate.Transaction.AdoNetWithDistrubtedTransactionFactory
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Optimize cache for minimal puts: False
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Connection release mode: auto
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Default batch fetch size: 1
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - echoing all SQL to stdout
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Statistics: disabled
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Deleted entity synthetic identifier rollback: disabled
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Query translator: NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Query language substitutions: {}
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - cache provider: NHibernate.Cache.NoCacheProvider, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
[TestRunnerThread] DEBUG NHibernate.Cfg.SettingsFactory - Wrap result sets: disabled
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Batcher factory: NHibernate.AdoNet.NonBatchingBatcherFactory, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Default entity-mode: Poco
[TestRunnerThread] INFO NHibernate.Cfg.SettingsFactory - Named query checking : enabled
[TestRunnerThread] INFO NHibernate.Impl.SessionFactoryImpl - building session factory
[TestRunnerThread] DEBUG NHibernate.Impl.SessionFactoryImpl - Session factory constructed with filter configurations : {}
[TestRunnerThread] DEBUG NHibernate.Impl.SessionFactoryImpl - instantiating session factory with properties: {'use_reflection_optimizer'='True', 'connection.provider'='NHibernate.Connection.DriverConnectionProvider', 'dialect'='NHibernate.Dialect.MsSql2008Dialect', 'connection.driver_class'='NHibernate.Driver.SqlClientDriver', 'connection.connection_string'='Server=MachineName\SQLEXPRESS;database=MySolution_Testing;Integrated Security=true;', 'proxyfactory.factory_class'='NHibernate.ByteCode.LinFu.ProxyFactoryFactory, Nhibernate.ByteCode.LinFu', 'show_sql'='true'}
[TestRunnerThread] DEBUG NHibernate.Connection.DriverConnectionProvider - Obtaining IDbConnection from Driver
[TestRunnerThread] DEBUG NHibernate.Connection.ConnectionProvider - Closing connection
As you can see, NHibernate seems to configure it self correctly, however, the final two lines seem to suggest that when a connection is actually asked for, something errors and it is all closed off. This is not reported back to NUnit and so it just sits there waiting indefinitely for a valid connection to use.
I have other projects that use a Fluent configuration that seem to function correctly, but these older projects use a SQL Compact database not SQL Express.
Is anyone able to suggest a solution to this issue ?
Thank you for your time.
The most likely cause of this is a stack overflow that crashes the nunit-agent.exe process. This causes the nunit.exe test runner to lose its connection to the agent process. See NUnit crashing with NHibernate for more information.
I know this is almost a year old but hopefully you or someone else may find this to be of use.
精彩评论