Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9068399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:10:55+00:00 2026-06-16T17:10:55+00:00

I have an app written in c# using nhibernate with an sqlite DB. For

  • 0

I have an app written in c# using nhibernate with an sqlite DB. For unit testing, I’m using xunit and an in-memory sqlite db.

I’m aware that the in-memory DB is destroyed when the session is closed so for testing, I use a single session and keep it open for the duration of the test. In most of my tests this works fine.

However, in a few cases, I need to test methods that make use of both ISession and IStatelessSession. After a little research, I settled on something similar to the approach described here. So the IStatelessSession is created using the ISession‘s connection like this:

statelessSession = factory.OpenStatelessSession(existingSession.Connection);

The problem is that this seems to cause some sort of conflict as soon as a change is persisted to the DB. If I do a transaction with session.SaveOrUpdate(new Entity() {...}) then that’s fine but if I then do a statelessSession.Get<Entity>(1) then it will fail with the error message “collection is not associated with any session”.

Normally, this error would indicate that the session is closed, but in this case, both sessions are still open and active.

If I do session.Get<Entity>(1) then it returns the entity as expected. Initially, I thought this might be because the session and stateless session were somehow out of sync so I replaced session.SaveOrUpdate.. with statelessSession.Insert(new Entity() {...}) and reran the test. Strangely, this made no difference. The regular session still works fine and the statelessSession is still broken.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:10:57+00:00Added an answer on June 16, 2026 at 5:10 pm

    Finally, I’ve found a solution to this whole thing:

    Eventually, I went back to my original query (a more complex query than the example above that returns multiple results) and tried various things while debugging through it, none of which shed any light on the problem.
    I then decided to remove the ‘where’ part of that query to see if it made any difference. Strangely, it did.
    It still failed, but this time I got a different exception: ‘could not execute query’, this also had an inner exception: ‘possible non-threadsafe access to the session’.

    The whole test runs on a single thread and I confirmed this by looking at the thread view when debugging. So I thought I’d hit another brick wall. However, after some googling, I found this blog post that describes the same problem and the solution: just update to the latest version of nhibernate!

    I updated from 3.1.0 to 3.3.1 (thanks to NUGet, this was a breeze) re ran the test and it worked. Put the where clause back and the test passed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a BlackBerry app that RSA encrypts a message using PKCS1FormatterEngine. This
I have written an app using dojo that allocates a lot of data during
I have a Facebook canvas app, written in AS3, and using the Adobe Facebook
I have an existing app written in PHP (using Kohana framework) and I want
I have this app written in VB.Net with winforms that shows some stats and
I have an AIR app initially written in Flex 3 that I had removed
I'm a beginning PHP developer. I have an app I've written that I would
I have a simple app written using SQL Server, Entity Framework, C# and WCF.
Say I have a mobile web app written using JQuery Mobile, this app retrieves
I have test app written on ruby, using Sinatra+Sequel. config.ru: require './main' run Sinatra::Application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.