views:

235

answers:

2

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?!

A: 

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.

KLE
+1  A: 

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.

Joseph
maybe you can explain that a bit further. Since I'm relatively new to .NET. I know where the pdbs reside, but how do I "figure out where the exception is first being thrown, and backtrack [it] in the stacktrace"? Sorry for me probably beeing very noobish ...
MAD9
@MAD9 In Visual Studio when you're debugging you can tell the IDE to break whenever an exception is thrown. If you have the pdbs included then it will break in the NH code so you can see the exception as it happens. Also, there is a stacktrace window in Visual Studio that allows you to see the sequence that was taken to get to that point. You can double click on any line item in the sequence and it will jump back/forward to that point so you can see the information at that level in the stack.
Joseph
does this apply to C# Express Edition, too?
MAD9
@MAD9 I'm not 100% sure but I think the debugging capabilities of C# Express are equivalent to what I've described.
Joseph
I think I got it. I found an option to disable debugging user code only
MAD9