I have this code that uses NHibernate
public bool ValidateUser(string username, string password)
{
bool loginResult;
using (var session = SessionFactory.Session)
{
session.BeginTransaction();
var makeQuery = session.Query<User>().SingleOrDefault(x => x.Username == username && x.Password == password);
loginResult = makeQuery != null;
}
return loginResult;
}
My SessionFactory looks like this
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;
using WebSite.DatabaseModels;
using System;
namespace GameServer.Repository
{
public class SessionFactory
{
private static string connString = System.Configuration.ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
private static ISessionFactory session;
private static object syncRoot = new Object();
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MySQLConfiguration
.Standard
.ConnectionString(connString))
.Mappings(m => m.FluentMappings
.AddFromAssemblyOf<UserMap>())
.ExposeConfiguration(UpdateSchema)
.BuildSessionFactory();
}
private static void UpdateSchema(Configuration cfg)
{
new SchemaUpdate(cfg);
}
public static ISession Session
{
get
{
if (session == null)
{
lock (syncRoot)
{
if (session == null)
session = CreateSessionFactory();
}
}
return session.OpenSession();
}
}
^
I tried putting a break point at the Session property, but that aint hit, but the exception is thrown at using (var session = SessionFactory.Session) and cant really see how I can fix it in error report

It would be better if you pasted the actual exception string (entire exception with stack trace) instead of an image.
As you can see in your stack trace, the exception happens in
cctorof yourSessionFactoryclass.cctoris a static constructor. Since you don’t have one explicitly, your code probably breaks on initializing static fields ofSessionFactoryclass.My best bet would be that you don’t have a connection string named
MySQLConnectionStringin your config file. In that case: