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 674249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:41:06+00:00 2026-05-14T00:41:06+00:00

I have created an multi thread application on IIS (ASP.NET MVC), When the threading

  • 0

I have created an multi thread application on IIS (ASP.NET MVC), When the threading server started it creates 10 thread and it’s execting workitems into the threads.

Usually my application working well, but some time i have got errors and i’m sure that problem is coming from fluent configuration. And I’m sure again i have made some mistake 🙂

Here is the my SessionFactory Class :

public class NHibernateHelper
{
    private static ISessionFactory sessionFactory;

    /// <summary>
    /// SessionFactory is static because it is expensive to create and is therefore at application scope.
    /// The property exists to provide 'instantiate on first use' behaviour.
    /// </summary>
    private static ISessionFactory SessionFactory
    {
        get
        {
            if (sessionFactory == null)
            {
                sessionFactory = CreateSessionFactory();
            }
            return sessionFactory;
        }
    }


    /// <summary>
    /// CreateSessionFactory
    /// </summary>
    /// <returns></returns>
    private static ISessionFactory CreateSessionFactory()
    {
        IPersistenceConfigurer dbConfigurer = MsSqlConfiguration.MsSql2005
            .ConnectionString("connection string ..")
                            .Cache(c => c
                                .UseQueryCache()
                                .ProviderClass<NoCacheProvider>()
                    ).ShowSql()
                    .CurrentSessionContext<ThreadStaticSessionContext>(); 
                    return Fluently
                            .Configure()
                            .Database(dbConfigurer)
                            .Mappings(mc =>
                            {
                                mc.FluentMappings.Add(typeof(UserMap));
                                mc.FluentMappings.Add(typeof(ApplicationMap));
                                mc.FluentMappings.Add(typeof(SubscriptionsMap));
                            })
                        .BuildSessionFactory();
    }


    public static ISession GetCurrentSession()
    {
        if (!CurrentSessionContext.HasBind(SessionFactory))
        {
            CurrentSessionContext.Bind(SessionFactory.OpenSession());
        }
        return SessionFactory.GetCurrentSession();
    }



    public static void DisposeSession()
    {
        var session = GetCurrentSession();
        session.Close();
        session.Dispose();
    }

    public static void BeginTransaction()
    {
        GetCurrentSession().BeginTransaction();
    }

    public static void CommitTransaction()
    {
        var session = GetCurrentSession();
        if (session.Transaction.IsActive)
            session.Transaction.Commit();
    }

    public static void RollbackTransaction()
    {
        var session = GetCurrentSession();
        if (session.Transaction.IsActive)
            session.Transaction.Rollback();
    }
}

Every thread is calling NHibernateHelper class with this line inside of itself ;

            var myobjectinstance = new ObjectInstance();
            NHibernateHelper.GetCurrentSession().Save( myobjectinstance );

I saw that, when i started server some time it has invoking 300.000 work item for test purpose successfully. But sometime it’s giving errors about 2-3 workitem.

The exception is :

[0] = {"An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.\r\n\r\n"}

Inner excetion is :

Object reference not set to an instance of an object.

Inner exception stack trace is :

    at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
    at System.Collections.Generic.Dictionary`2.set_Item(TKey key, TValue value)
    at NHibernate.Impl.SessionFactoryObjectFactory.AddInstance(String uid, String name, ISessionFactory instance, IDictionary`2 properties)
    at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
    at NHibernate.Cfg.Configuration.BuildSessionFactory()
    at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 
    in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 93

Any suggestion or help are welcome

  • 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-05-14T00:41:07+00:00Added an answer on May 14, 2026 at 12:41 am

    It looks like the CreateSessionFactory method is called multiple times. The sessionFactory static field access is not synchronized in this method which makes it not thread safe:

    private static ISessionFactory SessionFactory
    {
        get
        {
            if (sessionFactory == null)
            {
                sessionFactory = CreateSessionFactory();
            }
            return sessionFactory;
        }
    }
    

    Make sure to always synchronize access to shared resources in multithreaded applications. There’s a common used pattern in this situation called singleton.

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

Sidebar

Ask A Question

Stats

  • Questions 351k
  • Answers 351k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is what worked for me. I had to move… May 14, 2026 at 7:22 am
  • Editorial Team
    Editorial Team added an answer Fenomas' answer is wonderful and really covers everything on scaling.… May 14, 2026 at 7:22 am
  • Editorial Team
    Editorial Team added an answer A thread is not a process, so, no. (As a… May 14, 2026 at 7:22 am

Related Questions

I have created a .Net application to run on an App Server that gets
I am working on a multi-threaded application. This application started out as a single
I have a server application that receives information over a network and processes it.
Part of the development team I work with has been given the challenge of
I was googling for some advise about this and I found some links. The

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.