Tell don't ask

October 19, 2009

Fluent NHibernate Gotcha

Filed under: Fluent NHibernate,Gotchas,NHibernate,S#arp Architecture — telldontask @ 2:04 pm

It seems today’s the day for me to make daft mistakes and then blog about them.

If you’re using Fluent NHibernate (and there are many reasons why you should ;-)) and see this error message…

An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
  * Database was not configured through Database method.

System.IndexOutOfRangeException: Index was outside the bounds of the array.

at System.Array.InternalGetReference(Void* elemRef, Int32 rank, Int32* pIndices)
at System.Array.GetValue(Int32 index)
at NHibernate.Type.AbstractEnumType..ctor(SqlType sqlType, Type enumType)
at NHibernate.Type.EnumStringType..ctor(Type enumClass)
at FluentNHibernate.Mapping.GenericEnumMapper`1..ctor()

Do yourself a favour and check you haven’t left any empty Enums in your domain layer (the one that Fluent NHibernate is using to map to your database).

Funnily enough, if you do have an empty Enum, I don’t know, off the top of my head maybe something like this…

  1. public enum NoteType
  2. {
  4. }

Then you’ll probably get the error above.


  1. Awesome, saved me hours of searching for a solution.

    This was bugging me, as I copied the configuration from a past project that’s working perfectly and I couldn’t figure out why I was getting this error. Turned out I removed all entries of an enum making it empty. I added a temporary value and sure enough, the error cleared up.

    Thanks again!

    Comment by Mike — August 15, 2011 @ 5:49 pm | Reply

  2. You absolute diamond. Saved me alot of time too.

    Comment by Jordan — October 13, 2011 @ 2:16 pm | Reply

  3. Thank you, I was just scratching my head about this!

    Comment by Macs — July 7, 2013 @ 8:47 am | Reply

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Rubric Theme Blog at


Get every new post delivered to your Inbox.

%d bloggers like this: