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

  • SEARCH
  • Home
  • 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 3398810
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:41:41+00:00 2026-05-18T04:41:41+00:00

i have a .NET 3.5 solution with an asp.net(web site) project with fluentnhibernate and

  • 0

i have a .NET 3.5 solution with an asp.net(web site) project with fluentnhibernate and it’s test project(class library project).i’ve referenced the asp.net project in the test project and with all fluentnhibernate/nhibenate dlls.

What i fail to comprehend is that, on a run of a webform (hit from browser) let’s say Test.aspx, building of schema is successfull and i could see the tables in my database.
here is the method i call on Test.aspx.cs

public partial class Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ISession session = SessionManager.Instance.OpenSession();
       SessionManager.BuildSchema(session);
    }
}

i happen to use the same method in CanGenerateSchema method of my test class and it always fails

 [TestFixture]
public class CanGenerateSchemaTestSuite
{
    [Test]
    public void CanGenarateSchema()
    {
        ISession session = SessionManager.Instance.OpenSession();
        SessionManager.BuildSchema(session);
    }
}

here is the SessionManager i use :

public sealed class SessionManager
{
    private readonly ISessionFactory _sessionFactory;


    public static ISessionFactory SessionFactory
    {
        get { return Instance._sessionFactory; }
    }


    private ISessionFactory GetSessionFactory()
    {
        return _sessionFactory;
    }

    public static SessionManager Instance
    {
        get { return NestedSessionManager._sessionManager; }
    }

    public ISession OpenSession()
    {
        return Instance.GetSessionFactory().OpenSession();
    }


    private static Configuration SaveConfigs;

    private SessionManager()
    {
        try
        {

            if (_sessionFactory == null)
            {
            //from the debugging the code breaks from here when trying to get connectionstring.
                string constring = ConfigurationManager.AppSettings["localdb"].ToString();
                FluentConfiguration configuration = Fluently.Configure()
                    .Database(
                        MsSqlConfiguration.MsSql2005.ConnectionString(constring))
                    .Mappings(m =>
                    {
                        m.FluentMappings.AddFromAssemblyOf<myproject.model.Request>();
                        m.FluentMappings.AddFromAssemblyOf<myproject.model.Route>();
                    })
                    .ExposeConfiguration((x) =>
                    {
                        SaveConfigs = x;
                        x.SetProperty("current_session_context_class", "thread_static");

                    });
                _sessionFactory = configuration.BuildSessionFactory();
            }
        }
        catch (Exception ex)
        {
            Console.Write(ex.Message);

        }

    }


    public static void BuildSchema(ISession session)
    {
        var export = new SchemaExport(SaveConfigs);
        export.Execute(false,true,false,session.Connection,null);
    }

    class NestedSessionManager
    {
        internal static readonly SessionManager _sessionManager = new SessionManager();
    }
}

So from my comment the NullReferenceException happens when accessing the connectionstring. I don’t have the explanation on why that happens.I’m sure it’s some kind of gotchas, i can’t get over it.I would be very grateful if anyone could give me a hand here.thanks for reading.

  • 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-18T04:41:42+00:00Added an answer on May 18, 2026 at 4:41 am

    ConfigurationManager.AppSettings["localdb"] from Test.aspx would be pulling from your web.config file on a web project.

    That file wouldn’t be accessible to your test project (I’m assuming your tests are in a separate project from your web site). You should be able to get around this by adding an app.config file into your test project with the correct localdb settings or rather than using a configuration string, use FluentNHibernate’s fluent builder.

    Example app.config file:

    <?xml version="1.0"?>
    <configuration>
     <appSettings>
       <add key="localdb" value="yourconnectionstring" />
     </appSettings>
    </configuration>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just been handed an ASP.NET web site project, without a parent solution.
I have a solution that contains an ASP.NET Web Site (file-based) project. I'm currently
I have two projects in my solution   1- asp.net web project.   2-
I have an ASP.NET web site project that I want to debug, but when
I have an ASP.NET web site (not web project). It somehow stores references to
I have a web solution that contains 5 class libraries and one asp.net web
I have a Visual Studio 2008 solution with an ASP.NET Web Application project. I
I currently have an ASP.NET MVC 3 project, plus a class library project, that
When I worked on asp.net mvc web site project, I investigated different approaches for
I have a solution-file with ASP.NET Web Sites. When I build the solution with

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.