Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is NHibernate AdoTransaction's finalizer called?
    text
    copied!<p>I'm profiling out unit &amp; integration tests, and I find the a lot of the time is spent on the finalizer of NHibernate.Transaction.AdoTransaction - this means it is not getting disposed properly.</p> <p>I am not using AdoTransaction directly in the code, so it's probably used by some other object inside NHibernate. Any idea what I'm forgetting to Dispose?</p> <p>Here is my text fixture:</p> <pre><code>public abstract class AbstractInMemoryFixture { protected ISessionFactory sessionFactory; protected ILogger Logger { get; private set; } static readonly Configuration config; private static readonly ISessionFactory internalSessionFactory; static AbstractInMemoryFixture() { config = new NHibernateConfigurator().Configure(NHibernateConfigurators.SQLiteInMemory()); internalSessionFactory = config.BuildSessionFactory(); } [SetUp] public void SetUp() { const string sqliteInMemoryConnectionString = "Data Source=:memory:;Version=3;Pooling=False;Max Pool Size=1;"; var con = new SQLiteConnection(sqliteInMemoryConnectionString); con.Open(); new SchemaExport(config).Execute(false, true, false, true, con, System.Console.Out); var proxyGenerator = new ProxyGenerator(); sessionFactory = proxyGenerator.CreateInterfaceProxyWithTarget(internalSessionFactory, new UseExistingConnectionInterceptor(con)); Logger = new NullLogger(); ExtraSetup(); } [TearDown] public void TearDown() { var con = sessionFactory.OpenSession().Connection; if (con != null) { if (con.State == ConnectionState.Open) con.Close(); con.Dispose(); } } private class UseExistingConnectionInterceptor :IInterceptor { private readonly SQLiteConnection connection; public UseExistingConnectionInterceptor(SQLiteConnection connection) { this.connection = connection; } public void Intercept(IInvocation invocation) { if (invocation.Method.Name != "OpenSession" || invocation.Method.GetParameters().Length &gt; 0) { invocation.Proceed(); return; } var factory = (ISessionFactory) invocation.InvocationTarget; invocation.ReturnValue = factory.OpenSession(connection); } } protected virtual void ExtraSetup() { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload