-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Error while creating new instance of Configuration..pls help
PostPosted: Wed Apr 25, 2007 1:10 am 
Newbie

Joined: Sat Apr 21, 2007 2:12 am
Posts: 16
Hi All

I have written this code in startup class Program.cs and at runtime it generates error "The type initializer for 'NHibernate.Cfg.Configuration' threw an exception." on line "nhConfig = new Configuration();" whereas i have defined configuration file too. What could be the possible reason? Pls help

---------------------------------------------

using System;
using System.Windows.Forms;
using NHibernate;
using NHibernate.Cfg;

namespace ExampleApplication
{
public sealed class Program
{
private static Configuration nhConfig;
private static ISessionFactory nhFactory;

[STAThread]
static void Main()
{
nhConfig = new Configuration();
nhConfig.AddAssembly("ExampleApplication");
nhFactory = nhConfig.BuildSessionFactory();

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LogInForm());
}

public static ISession NHSession
{
get {return nhFactory.OpenSession(); }
}

private Program() {}
}
}
--------------------------------------------------------


App.config



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e080" />
</configSections>

<log4net>
<appender name="rollingFile" type="log4net.Appender.RollingFileAppender, log4net" >
<param name="File" value="log.txt" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Date" />
<param name="DatePattern" value="yyyy.MM.dd" />
<param name="StaticLogFileName" value="true" />
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
</layout>
</appender>
<root>
<priority value="DEBUG" />
<appender-ref ref="rollingFile" />
</root>
</log4net>

<nhibernate>

<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
<add key="hibernate.connection.connection_string" value="Data Source=SQLSERVER;Initial Catalog=ORMExample;Integrated Security=True;Pooling=False" />

<add key="hibernate.show_sql" value="true" />

</nhibernate>


</configuration>


Thanks and Regards
Gaurav Bhatia


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 1:24 am 
Newbie

Joined: Sat Apr 21, 2007 2:12 am
Posts: 16
The Inner Exception which is throws is

{"Could not load file or assembly 'log4net, Version=1.2.0.30714, Culture=neutral, PublicKeyToken=b32731d11ce58905' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)":"log4net, Version=1.2.0.30714, Culture=neutral, PublicKeyToken=b32731d11ce58905"}

Though I have added log4net.dll in references, then what could be the reason for it not loading log4net?

Thanks

Regards,
Gaurav


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 25, 2007 1:35 am 
Newbie

Joined: Sat Apr 21, 2007 2:12 am
Posts: 16
Problem Solved.
In App.Config file, i was giving the public key token for nhibernate "b77a5c561934e086" where as it was supposed to be "b77a5c561934e089"..

:)

Gaurav


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.