Michael Niemand
Michael Niemand

Reputation: 1754

how to debug a NHibernate mapping?

I use NHibernate (2.0.1GA) with my project. At runtime I get the

Invalid Cast (check your mapping for property type mismatches); 
[...]

So it only says its unable to cast something. Thats a bit unprecise imho.

My mapping file is pretty big (master table with about 50 colums plus 11 subsets). How do I find the invalid cast without checking every line in it against the corresponding classes & tables?!

Upvotes: 4

Views: 2218

Answers (3)

Mikael Engver
Mikael Engver

Reputation: 4768

You probabaly want to catch the NHibernate.MappingException that gets thrown. One way to do that is to go to Exception Settings ( Debug | Windows | Exception Settings or [Ctrl-Alt-E])

You can then check the box beneth the Common Language Runtime Exception folder.

enter image description here

Upvotes: 0

Joseph
Joseph

Reputation: 25523

Get a hold of the pdbs (or just get the source), and figure out where the exception is first being thrown, and then backtrack in the stacktrace until you see what it is trying to cast.

Upvotes: 1

KLE
KLE

Reputation: 24169

Does this happen when you run a specific request? Then you have a more restricted suspects set :-) : only the tables and columns implied...

I tend to take away tables from the request, to discover what table has a problem. Then possibly the same attitude for fields...


Otherwise, if it happens when your NHibernate verifies all entities, you can use dichotomy to localize your problem.

Upvotes: 0

Related Questions