[Mono-aspnet-list] FluentNHibernate InvalidCastException at creating SessionFactory

gajcz gajczewski at gmail.com
Fri Aug 26 08:00:13 EDT 2011


I'm trying to introduce Fluent NHibernate in my .NET MVC 3 project but I
found some problem with Npgsql library. When the connection is being
configured and set up for the first time I receive following exception:

An invalid or incomplete configuration was used while creating a
SessionFactory. Check PotentialReasons collection, and InnerException for
more detail.
Stack Trace:
  at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory ()
[0x00000] in <filename unknown>:0 
  at OnlineJudge.Web.Controllers.NHibernateHelper..cctor () [0x00013] in

Inner Exception:
Cannot cast from source type to destination type.
Stack Trace:
() [0x00000] in <filename unknown>:0 
  at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords
(NHibernate.Dialect.Dialect dialect, IConnectionHelper connectionHelper)
[0x00000] in <filename unknown>:0 
  at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update (ISessionFactory
sessionFactory) [0x00000] in <filename unknown>:0 
  at NHibernate.Impl.SessionFactoryImpl..ctor (NHibernate.Cfg.Configuration
cfg, IMapping mapping, NHibernate.Cfg.Settings settings,
NHibernate.Event.EventListeners listeners) [0x00000] in <filename unknown>:0 
  at NHibernate.Cfg.Configuration.BuildSessionFactory () [0x00000] in
<filename unknown>:0 
  at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory ()
[0x00000] in <filename unknown>:0

The exception occurs inside my NHibernateHelper class where I've got:

var databaseConfiguration =

sessionFactory = Fluently.Configure()
                .Mappings(m =>

In Web.config I've got appropriate section for DbProviderFactory:
    <add name="Npgsql Data Provider" invariant="Npgsql" support="FF"
description=".Net Framework Data Provider for Postgresql Server"
type="Npgsql.NpgsqlFactory, Npgsql, Version=, Culture=neutral,
PublicKeyToken=5d8b90d52f46fda7" />

It all works on Windows when I've got "Version=" instead of
"Version=" which is on Linux.

Also before using NHibernate the Npgsql worked fine on both systems:
var connection = new NpgsqlConnection(connectionString);

I also tried to get NpgsqlFactory on my own:
var factory = Npgsql.NpgsqlFactory.Instance;
var connection = factory.CreateConnection();
var factory = DbProviderFactories.GetFactory("Npgsql");
var connection = factory.CreateConnection();
and in both cases the same InvalidCastException was thrown, so maybe it's
the same issue.

Does anyone know where is the problem or what I'm doing wrong? Any idea what
can it be and maybe where is better to ask for help?

Versions I use:
- OpenSUSE 11.3
- Mono 2.10.2 (default)
- mono-data-postgresql 2.10.2-36.1 (default)
- PostgreSQL 8.4
- NHiberante 3.1 (Fluent 1.2)

View this message in context: http://mono.1490590.n4.nabble.com/FluentNHibernate-InvalidCastException-at-creating-SessionFactory-tp3770661p3770661.html
Sent from the Mono - ASP.NET mailing list archive at Nabble.com.

More information about the Mono-aspnet-list mailing list