I am still failing to configure fluent nhibernate in my project. switching from java with spring and hibernate, nhibernate was my first choise and without the need to define mapping xmls it is now fluent nhibernate. But I always get this error
ystem.TypeInitializationException: The type initializer for 'Altv_Roleplay.Database.Config.NHibernateHelper' threw an exception.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
---> NHibernate.MappingException: Could not compile the mapping document: (XmlDocument)
---> System.TypeInitializationException: The type initializer for 'NHibernate.Cfg.NamedXmlDocument' threw an exception.
---> System.NotSupportedException: A non-collectible assembly may not reference a collectible assembly.
at System.Reflection.Emit.ModuleBuilder.GetTypeRef(QCallModule module, String strFullName, QCallModule refedModule, String strRefedModuleFileName, Int32 tkResolution)
at System.Reflection.Emit.ModuleBuilder.GetTypeRefNested(Type type, Module refedModule, String strRefedModuleFileName)
at System.Reflection.Emit.ModuleBuilder.GetTypeTokenWorkerNoLock(Type type, Boolean getGenericDefinition)
at System.Reflection.Emit.ModuleBuilder.GetTypeTokenInternal(Type type, Boolean getGenericDefinition)
at System.Reflection.Emit.ILGenerator.Emit(OpCode opcode, Type cls)
at System.Xml.Serialization.CodeGenerator.Castclass(Type target)
at System.Xml.Serialization.CodeGenerator.InternalConvert(Type source, Type target, Boolean isAddress)
at System.Xml.Serialization.SourceInfo.InternalLoad(Type elementType, Boolean asAddress)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteElement(SourceInfo source, ElementAccessor element, String arrayName, Boolean writeAccessor)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteElements(SourceInfo source, String enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, String arrayName, Boolean writeAccessors, Boolean isNullable)
at System.Xml.Serialization.XmlSerializationWriterILGen.WriteMember(SourceInfo source, String choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, Boolean writeAccessors)
at System.Xml.Serialization.XmlSerializationWriterILGen.GenerateTypeElement(XmlTypeMapping xmlTypeMapping)
at System.Xml.Serialization.XmlSerializationWriterILGen.GenerateElement(XmlMapping xmlMapping)
at System.Xml.Serialization.TempAssembly.GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace)
at System.Xml.Serialization.TempAssembly..ctor(XmlMapping[] xmlMappings, Type[] types, String defaultNamespace, String location)
at System.Xml.Serialization.XmlSerializer.GenerateTempAssembly(XmlMapping xmlMapping, Type type, String defaultNamespace, String location)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)
at NHibernate.Cfg.NamedXmlDocument..cctor()
--- End of inner exception stack trace ---
at NHibernate.Cfg.NamedXmlDocument..ctor(String name, XmlDocument document)
at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader, String name)
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.LoadMappingDocument(XmlReader hbmReader, String name)
at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name)
at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc)
at FluentNHibernate.PersistenceModel.Configure(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Altv_Roleplay.Database.Config.NHibernateHelper.FluentConfigure() in E:\dev\ls-reallife-altv\MAPPE\Altv-Roleplay\Database\Config\NHibernateHelper.cs:line 40
at Altv_Roleplay.Database.Config.NHibernateHelper..cctor() in E:\dev\ls-reallife-altv\MAPPE\Altv-Roleplay\Database\Config\NHibernateHelper.cs:line 23
--- End of inner exception stack trace ---
at Altv_Roleplay.Database.Config.NHibernateHelper.GetCurrentSession() in E:\dev\ls-reallife-altv\MAPPE\Altv-Roleplay\Database\Config\NHibernateHelper.cs:line 26
at Altv_Roleplay.Database.DatabaseHandler.LoadAllPlayerCharacters() in E:\dev\ls-reallife-altv\MAPPE\Altv-Roleplay\Database\DatabaseHandler.cs:line 86
at Altv_Roleplay.Main.OnStart() in E:\dev\ls-reallife-altv\MAPPE\Altv-Roleplay\Main.cs:line 48
at AltV.Net.ModuleWrapper.OnStartResource(IntPtr serverPointer, IntPtr resourcePointer, String resourceName, String entryPoint)
namespace Altv_Roleplay.Database.Mappings
{
public partial class AccountCharactersMapping : ClassMap<Accounts_Characters>
{
public AccountCharactersMapping()
{
Id(x => x.charId).GeneratedBy.Native();
Map(x => x.charname);
...
}
}
}
My Entity:
namespace Altv_Roleplay.models
{
public class Accounts_Characters
{
public virtual int charId { get; set; }
public virtual string charname { get; set; }
....
}
}
I get this error when I try to open the session at:
internal static void LoadAllPlayerCharacters()
{
ISession session = NHibernateHelper.GetCurrentSession(); // Here is when the Error appears
using (ITransaction tx = session.BeginTransaction())
{
...
}
Hello,
I am still failing to configure fluent nhibernate in my project. switching from java with spring and hibernate, nhibernate was my first choise and without the need to define mapping xmls it is now fluent nhibernate. But I always get this error
My Configuration looks like:
My Mapping:
My Entity:
I get this error when I try to open the session at:
I also tried to add a hibernate xml config:
But still no success. I tried it with netcoreapp3.1, net5.0 but now I am forced to switch to net6.0 due to other dependencies