I am using NHibernate to pull some objects from my database:
Dim RpList As List(Of ReferencePackage) = session.QueryOver(Of ReferencePackage).OrderBy(Function(x) x.Name).Asc.List
I then try to assign this collection as the datasource to a ListBox:
ReferencePackagesListBox.DataSource = RpList
When I do this, Visual Studio immediately stops debugging. I have a try/catch surrounding the DataSource assignment, and I have also disabled “Only my code” in the debugging options; it does not throw an exception.
I have another List of objects I am pulling from NHibernate as well that seem to bind to the ListBox just fine in this same way. I can only assume that the issue is with binding the objects to the control. I have tried assigning the DisplayMember and ValueMember before assigning the DataSource but it has not helped at all. I have also tried converting the IList from NHibernate to a BindingList but it still crashes.
Any help would be very appreciated.
It turns out the answer is the same as another question I have on here.
Basically – binding NHibernate Proxy objects can behave strangely sometimes. Part of that strange behavior is that it can cause Visual Studio to stop debugging without throwing an exception, or giving any warning. The solution is to use a view class of your object and bind to the view.