CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Kyle Baley - The Coding Hillbilly

"We are stuck with technology when what we really want is just stuff that works" -- Douglas Adams

NHibernate and ASP.NET MVC

Am playing with ASP.NET MVC these days in preparation for a couple o' presentations on it. Jeffrey Palermo's CodeCampServer sample app has proven invaluable in this regard even if I have become overly cognizant that I'm ripping off his ideas.

In my own version, I'm also referencing NHibernate in my data access layer and whenever I do that, I always forget which assemblies it requires to tag along with it. In my sample, I brought over NHibernate.dll, Iesi.Collections.dll, and log4net.dll into my lib folder and added the reference to NHibernate.dll from the project. Wired up all my repositories, hooked in the IoC container (in this case, Windsor) and loaded the page:


Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Not overly helpful and although my lead-up to this has made it painfully obvious, let me tell you when you've also added the IoC container and three other layers 'twixt the UI and the DataAccess layer, 'tweren't altogether clear just what was causing this problem.

In fact, even when I reverted all the code in the control back to use the simplest possible controller action, I still got this error. The reason being: I still had the reference to the DataAccess project as well as the references to its classes in the Windsor container. Which means it was still trying to load NHibernate.

And NHibernate (or at least the version of it I have) requires, along with the other assemblies mentioned above, a reference to Castle.DynamicProxy.dll. So I dropped the assembly into the lib folder and it came along for the ride the next time I compiled. Problem solved. Reminder stored.

Kyle the Proxied



Comments

Jeffrey Palermo said:

I also have an ASP.NET MVC sample app that uses NHibernate to get at Northwind.

code.google.com/.../palermo

# January 18, 2008 12:00 PM

james.kovacs said:

When you get TypeLoadExceptions, it's time to pull to FusLogVw.exe, which ships with the .NET Framework SDK. It will tell you exactly which assembly load is failing and why. I should probably write a blog post about it sometime... Added to my increasingly long To-Do List. :)

# January 18, 2008 11:32 PM

Srihari Kothapalli said:

Useless article.. Please do not try to mislead and waste browsers time with such title. "NHibernate and ASP.NET MVC" I would have expected to see some introduction on both of these etc etc
# June 20, 2008 6:55 AM

Kyle Baley said:

Oy, angry, angry people out here in internet-land. But since you said please, I'll fire the marketing firm I use to name my posts.

# June 20, 2008 7:02 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

Our Sponsors