Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nhibernate error - The type initializer for 'NHibernate.Cfg.Configuration' threw an exception.

Status
Not open for further replies.

dstxaix

Programmer
Dec 22, 2005
78
0
0
US
I am trying my first vb.net + nhibernate + mysql project using vb 2010 express on windows 8

I am getting below error in my log file
Code:
2013-05-15 11:00:27,312 [8] INFO  -      [Log4NetAssembly1] Form1_Load() - Start
2013-05-15 11:00:27,402 [8] ERROR -      [Log4NetAssembly1] Form1_Load() - The type initializer for 'NHibernate.Cfg.Configuration' threw an exception.
2013-05-15 11:00:27,402 [8] INFO  -      [Log4NetAssembly1] Form1_Load() - Finish
App.config contains following:
Code:
<?xml version="1.0"?>
<configuration>
  <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <!-- Database connection settings -->
      <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
      <property name="connection.connection_string">Server=localhost:3306;Database=test;User ID=root;Password=test;</property>
      <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="show_sql">true</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu</property>

      <!-- -->
      <mapping resource="Dummy.hbm.xml"/>
    </session-factory>
  </hibernate-configuration>
  <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information"/>
        </switches>
        <sharedListeners>
            <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>
Dummy.hbm.xml contains
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="log4netassembly1">
  <class name="log4netassembly1.Dummy" table="dummy">
    <id name="Id">
      <column name="id" />
      <generator class="increment" />
    </id>

    <property name="Text">
      <column name="text"  />
    </property>

  </class>
</hibernate-mapping>
nhibernate.cfg.xml contains the following
Code:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
        <property name="connection.connection_string">Server=localhost:3306;Database=test;User ID=root;Password=Appavi59;</property>
        <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="show_sql">true</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu</property>

        <!-- -->
      <mapping resource="Dummy.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
form1.vb contains
Code:
Imports NHibernate
Imports NHibernate.Cfg

Public Class Form1

    Public Shared logger As log4net.ILog

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            logger = log4net.LogManager.GetLogger("Log4NetAssembly1")
            logger.Info("Form1_Load() - Start")
            Dim config As New Configuration
            config.Configure()
            config.AddAssembly("log4netassembly1")
            config.AddFile("Dummy.hbm.xml")

            Dim myFactory As ISessionFactory = config.BuildSessionFactory

            Dim mySession As ISession = myFactory.OpenSession

            Dim myTransaction As ITransaction = mySession.BeginTransaction

            Dim cust As New Dummy
            cust.stext = "testest"

            mySession.Save(cust)
            myTransaction.Commit()
            mySession.Close()
        Catch ex As Exception
            logger.Error("Form1_Load() - " & ex.Message)
        Finally
            logger.Info("Form1_Load() - Finish")
        End Try
    End Sub
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top