Sp1r1t
Mitglied
Hallo,
ich kann bisher keine Erfahrung mit NHibernate aufweisen, da ich aber für dieses Projekt allerdings NHibernate nutzen muss, wenn ich mich an euch.
Randinformationen:
- Sprache: C#
- .NET Framework: .NET Core 2.2
- NHibernate Version: 5.2.5
Die Events werden vom Main-Projekt ausgelöst und gehandelt und funktioniern ohne Probleme.
Client ist eine Klasse, welche für das Problem irrelevant ist.
Der Output des Exception Handlings in der main.cs
Ich hoffe jemand kann mir helfen.
Mit freundlichen Grüßen
Sp1r1t
ich kann bisher keine Erfahrung mit NHibernate aufweisen, da ich aber für dieses Projekt allerdings NHibernate nutzen muss, wenn ich mich an euch.
Randinformationen:
- Sprache: C#
- .NET Framework: .NET Core 2.2
- NHibernate Version: 5.2.5
C#:
using System;
using System.Reflection;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Dialect;
namespace project
{
public class Main : Script
{
private ISessionFactory sefact;
public Main()
{
Console.log("Program started");
try
{
this.sefact = this.Connection();
} catch (Exception e)
{
// Debug
Console.log("-------- First Level Exception --------");
Console.log(e.Message);
Console.log(e.StackTrace);
Console.log("-------- second Level Exception --------");
Console.log(e.InnerException.Message);
Console.log(e.InnerException.StackTrace);
Console.log("-------- third Level Exception --------");
Console.log(e.InnerException.InnerException.Message);
Console.log(e.InnerException.InnerException.StackTrace);
}
}
[ServerEvent(Event.PlayerConnected)]
public void PlayerJoin(Client client)
{
client.SetData("loginCount", 0);
}
[RemoteEvent("OnPlayerSpawn")]
public void OnPlayerSpawn(Client client, string username, string password)
{
Console.log($"{username} tries to log in with {client.GetData("loginCount")} tries");
User currentUser = this.GetUser(username);
if (currentUser != null && currentUser.password == password)
{
client.SetData("loginCount", 0);
client.TriggerEvent("loginResult", 1);
}
else
{
if (client.GetData("loginCount") < 2)
{
int value = client.GetData("loginCount");
Console.log($"Login count stored: {value}");
int loginCount = value += 1;
Console.log($"Login count: {loginCount}");
client.SetData("loginCount", loginCount);
client.TriggerEvent("loginResult", 0);
}
else
{
client.TriggerEvent("loginResult", 0);
client.SetData("loginCount", 0);
client.Kick();
}
}
}
private ISessionFactory Connection()
{
var cfg = new Configuration();
cfg.DataBaseIntegration(x =>
{
x.ConnectionString = "Server=127.0.0.1;Database=dbname;Uid=xxxx;Pwd=xxxx;";
x.Dialect<MySQLDialect>();
});
cfg.AddAssembly(Assembly.GetExecutingAssembly());
return cfg.BuildSessionFactory();
}
private User GetUser(string username)
{
try
{
using (var session = sefact.OpenSession())
{
try
{
using (var tx = session.BeginTransaction())
{
try
{
var users = session.CreateCriteria<User>().List<User>();
foreach (var user in users)
{
if (user.username == username)
{
return user;
}
}
tx.Commit();
} catch (Exception e)
{
NConsole.log(e.Message);
}
}
} catch (Exception e)
{
Console.log(e.Message);
}
}
}
catch (Exception e)
{
Console.log(e.Message);
}
return null;
}
}
}
Client ist eine Klasse, welche für das Problem irrelevant ist.
C#:
namespace project
{
class User
{
public virtual int id { get; set; }
public virtual string username { get; set; }
public virtual string password { get; set; }
public virtual string mail { get; set; }
public virtual int whitelist { get; set; }
}
}
XML:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns = "urn:nhibernate-mapping-2.2"
assembly = "project" namespace = "project">
<class name = "User">
<id name = "id">
<generator class = "native"/>
</id>
<property name = "username"/>
<property name = "password"/>
<property name = "mail"/>
<property name = "whitelist"/>
</class>
</hibernate-mapping>
Code:
-------- First Level Exception --------
The type initializer for 'NHibernate.Cfg.Environment' threw an exception.
at NHibernate.Cfg.Configuration.Reset() in D:\BuildAgent\work\30546188361a242\src\NHibernate\Cfg\Configuration.cs:line 174
at project.Main.Connection() in main.cs:line 79
at project.Main..ctor() in main.cs:line 21
-------- second Level Exception --------
The type initializer for 'NHibernate.NHibernateLogger' threw an exception.
at INHibernateLogger NHibernate.NHibernateLogger.For(Type type) in D:\BuildAgent\work\30546188361a242\src\NHibernate\Logging.cs:line 110
at static NHibernate.Cfg.Environment() in D:\BuildAgent\work\30546188361a242\src\NHibernate\Cfg\Environment.cs:line 300
-------- third Level Exception --------
Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
at string NHibernate.NHibernateLogger.GetNhibernateLoggerClass()
at static NHibernate.NHibernateLogger() in D:\BuildAgent\work\30546188361a242\src\NHibernate\Logging.cs:line 60
Code:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeInitializationException: The type initializer for 'NHibernate.Cfg.Environment' threw an exception.
---> System.TypeInitializationException: The type initializer for 'NHibernate.NHibernateLogger' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
at string NHibernate.NHibernateLogger.GetNhibernateLoggerClass()
at static NHibernate.NHibernateLogger() in D:\BuildAgent\work\30546188361a242\src\NHibernate\Logging.cs:line 60
--- End of inner exception stack trace ---
at INHibernateLogger NHibernate.NHibernateLogger.For(Type type) in D:\BuildAgent\work\30546188361a242\src\NHibernate\Logging.cs:line 110
at static NHibernate.Cfg.Environment() in D:\BuildAgent\work\30546188361a242\src\NHibernate\Cfg\Environment.cs:line 300
--- End of inner exception stack trace ---
at void NHibernate.Cfg.Configuration.Reset() in D:\BuildAgent\work\30546188361a242\src\NHibernate\Cfg\Configuration.cs:line 174
at ISessionFactory project.Main.Connection() in main.cs:line 79
at new project.Main() in main.cs:line 21
Ich hoffe jemand kann mir helfen.
Mit freundlichen Grüßen
Sp1r1t