Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Data Binding in Winforms C#?

I'm getting alot of issues lately in a project im working on with databinding. When im about to display a certain form that has bindings inside its controls, the .Show method throws expcetions regarding the binding - "Cannot bind to property or column on datasource. Parameter name: dataMember.".

Now, I'm quite aware this is a rather generic error message, but i can't find a decent way to get any info on which binding failed, which control, which data source/member and so on.

Is there a good way to find this?

like image 766
Ran Sagy Avatar asked Oct 26 '22 23:10

Ran Sagy


2 Answers

I guess some general debugging tips will help:

When debugging, is there an inner exception with more information?

Another tip is to turn on 'Show external code' in the stack trace window. This will allow you to go further down into the stack to the .Net Framework code itself. Turn on your locals window for information on the content of the current context, this might lead you to the problem.

Also be sure to turn on 'Break on exception' for all CLR exceptions.

Good luck.

like image 174
Gerrie Schenck Avatar answered Nov 08 '22 03:11

Gerrie Schenck


Well, I'm stumped. One of the controls in the form is a UserControl i made, Which contains some bindings in it.

This used to work fine. Now, I've added inhertience from IEnumerable to my control so it can return certain objects inside it for a different feature i tried adding. Now, If i 'Step-Into' the .Show call, I reach the IEnumrable implementation i made in a certain case.

Although it returned an empty collection at this time, since i had no elements to return, That apparently caused the ArgumentException that i got with the DataBinding for some reason. The moment i remove the IEnumrable inheritence from my control, Everything is back to normal.

I'm completely clueless as to why this happened.

like image 39
Ran Sagy Avatar answered Nov 08 '22 02:11

Ran Sagy