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. {
  3.     
  4. }

Then you’ll probably get the error above.

S#arp Architecture WCF Gotcha

Filed under: ASP.NET MVC,Castle,MVC,S#arp Architecture — telldontask @ 7:33 am

We’ve recently adopted the excellent S#arp Architecture for our projects. I highly recommend taking a look at the project site.

On Friday I created a simple WCF service using S#arp’s Northwind sample site for  reference.

Using WcfTestClient I located my service and attempted to test one of the methods, only to get the following error.

Could not load file or assembly ‘Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc’ or one of its dependencies. The system cannot find the file specified.

I looked for the usual suspects (rogue entries in the GAC, searching the c:\ drive for instances of Castle.Windsor) but couldn’t find the problem.

Eventually I discovered this code in the sample site’s web.config.

  1. <runtime>
  2.   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  3.     <dependentAssembly>
  4.       <assemblyIdentity name="Castle.Windsor" publicKeyToken="407dd0808d44fbdc" culture="neutral"/>
  5.       <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="2.0.0.0"/>
  6.     </dependentAssembly>
  7.   </assemblyBinding>
  8. </runtime>

Copying this to the web.config for my WCF service solved the problem.

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.