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

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


Hi,

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:

*FluentNHiberante.Cfg.FluentConfigurationException*
Message:
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
/.../*NHibernateHelper.cs:34*

Inner Exception:
*System.InvalidCastException*
Message:
Cannot cast from source type to destination type.
Stack Trace:
  at
NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare
() [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 =
PostgreSQLConfiguration.PostgreSQL82.ConnectionString(connectionString);

sessionFactory = Fluently.Configure()
                .Database(databaseConfiguration)
                .Mappings(m =>
                    {
                       
m.FluentMappings.AddFromAssemblyOf<Models.MyClass>();
                    })
                .BuildSessionFactory();

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


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

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


I also tried to get NpgsqlFactory on my own:
var factory = Npgsql.NpgsqlFactory.Instance;
var connection = factory.CreateConnection();
...
or:
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