-1

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. I have seen many articles but did not receive the accurate answer.

I have tried all the solutions available but none of them worked for me..

i have already mentioned connection string in app.config file

I am working with NHibernate..

and c# code is :

        Bind<ISessionFactory>()
            .ToMethod
            (
                e =>
                    Fluently.Configure()
                    .Database(MsSqlConfiguration.MsSql2012.ConnectionString(c => c.FromConnectionStringWithKey("JustBlogDbConnString")))
                    .Cache(c => c.UseQueryCache().ProviderClass<HashtableCacheProvider>())
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Post>())
                    .ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(true, true, false))
                    .BuildConfiguration()
                    .BuildSessionFactory()
            )
            .InSingletonScope();

plzz anyone help...

1 Answers1

0

One of your values used in the lamdas is null. To locate which one, please try:

Bind<ISessionFactory>().ToMethod(
    e => 
    {
        var x1 = Fluently.Configure();
        var x2 = x1.Database(MsSqlConfiguration.MsSql2012.ConnectionString(c => c.FromConnectionStringWithKey("JustBlogDbConnString")));
        var x3 = x2.Cache(c => c.UseQueryCache().ProviderClass<HashtableCacheProvider>());
        var x4 = x3.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Post>());
        var x5 = x4.ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(true, true, false));
        var x6 = x5.BuildConfiguration();
        x6.BuildSessionFactory();
    })
    .InSingletonScope();

Basically the idea is to split out the massively long "fluent" line into smaller chunks so the error can be located more clearly. Once you've located the offending lamda you may need to do some more splitting to find which reference (if you have multiple nested references) is actually null.

My money's on the name of the connection string being wrong.

Immersive
  • 1,684
  • 1
  • 11
  • 9