question

EmonHaque-1485 avatar image
0 Votes"
EmonHaque-1485 asked EmonHaque-1485 edited

Why do these ICollectionViews remain null?

Previously, I'd mentioned an Issue with Visual Studio 2019 Community (16.9.4) that it got into the setter before instantiating the viewmodel. On the next day, I got an update so now it's 16.9.5 BUT that didn't solve the issue and I thought it's just like the xaml binding error I used to get in output window, when worked with xaml files in previous versions of my app, that doesn't throw runtime exception. And that time it caused the issue only in debug mode, I don't get that error when I run with CTRL+F5.

Now in two other views I've same problem. In the Edit Transaction view even though I've initialized the Heads in the constructor it remains null:

96934-1.gif

same with the Edit Lease view, Spaces is null:

96840-2.gif

this time it actually throws runtime exception (EDIT in release mode and run without debug with CTRL+F5) in both Edit Transaction and Lease views BUT as before it doesn't in Edit Space view:

97011-3.gif

These combobox like controls have been used in exact same way in all these three views. If I set a breakpoint in the constructor of either Transaction or Lease view and let it hit and go I don't get that exception!

The only difference between the Space view and Transaction as well as Lease view is that viewmodels for those have overridden a virtual method, setStatesOnClone, which is called in the setOnEdit method of EditBase, base class for all edit views.

EDIT

When I click the edit button, at the bottom right corner of those views, the setOnEdit is called. Tried to upload one more gif, less than 3mb, several times in between last 2 paragraphs, but I couldn't, why?

dotnet-csharpwindows-wpf
1.gif (2.0 MiB)
2.gif (2.1 MiB)
3.gif (2.7 MiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EmonHaque-1485 avatar image
0 Votes"
EmonHaque-1485 answered EmonHaque-1485 edited

The problem is for some ICollectionView the underlying CollectionViewSource gets deleted/garbage collected at runtime! For example, in Edit Lease view, I've two Refresh() calls:

 protected override void setStatesOnClone() {
     Spaces.Refresh();
     ReceivableHeads.Refresh();
 } 

and I always got the exception on Spaces, never in ReceivableHeads. Now if I keep a reference field spaces, a CollectionViewSource, in EditLeaseVM and heads in EditTransactionVM, I don't get any error:

96965-test.gif

it took a long time to figure out!


test.gif (2.8 MiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.