nhibernate / fluent-nhibernate

Fluent NHibernate!
BSD 3-Clause "New" or "Revised" License
1.66k stars 686 forks source link

nhibernate has invalid child element 'add' #615

Closed listentomyblues closed 1 year ago

listentomyblues commented 1 year ago

I'm having issues running my application where it uses nhibernate. the runtime issue I'm getting is:

The element 'session-factory' in namespace 'urn:nhibernate-configuration-2.2' has invalid child element 'add' in namespace 'urn:nhibernate-configuration-2.2'. List of possible elements expected: 'property, mapping, class-cache, collection-cache, event, listener' in namespace 'urn:nhibernate-configuration-2.2'.

My code is:

protected void Initialization(Assembly[] assemblies, string fileName)
        {
            logger.DebugFormat( @"Initialization Start {0:HH:mm:ss.fff}", DateTime.Now );

            SessionFactory = Fluently
                .Configure(
                    new Configuration()
                        .Configure( fileName )
                )
                .Mappings( x => assemblies
                    .ForEach( a => x
                        .FluentMappings
                        .AddFromAssembly( a )
                        .Conventions
                        .Add(
                            AutoImport.Never(),
                            DefaultCascade.All(),
                            DefaultLazy.Always(),
                            ForeignKey.EndsWith( "Id" ),
                            PrimaryKey.Name.Is( c => c.EntityType.Name + "Id" ),
                            Table.Is( c => "[" + c.EntityType.Name + "]" )
                        )
                    )
                )
                .BuildSessionFactory();

            logger.DebugFormat( @"Initialization Finish {0:HH:mm:ss.fff}", DateTime.Now );
        }

filename contents:

<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <add name="CoreDbContext" connectionString="Data Source=(localdb)\\mssqllocaldb;Initial Catalog=Database_name;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
        <property name="show_sql">true</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    </session-factory>
</hibernate-configuration>

I already installed Full-Text and Semantic Extractions for Search but it still didn't fix my issue

listentomyblues commented 1 year ago

I manage to fix the issue. I changed the <add> in the xml file into <property>