locked
Setting ItemsSource sends me to App.g.i.vb

    Question

  • I have the following code in my codebehind:

    Dim temp As Object = New SetFinder().FindSets(Me.wrapCards.Children.Cast(Of Card).ToList()).Select(Function(s) s.Select(Function(c) CType(Me.wrapCards.Children(c), Card)).ToArray()).ToArray()
    System.Diagnostics.Debug.WriteLine(temp.GetType().ToString())
    'Me.itmCurrentSets.ItemsSource = New SetFinder().FindSets(Me.wrapCards.Children.Cast(Of Card).ToList()).Select(Function(s) s.Select(Function(c) CType(Me.wrapCards.Children(c), Card)).ToArray()).ToArray()
    Me.itmCurrentSets.ItemsSource = {({New Card(True, rnd), New Card(True, rnd), New Card(True, rnd)}), ({New Card(True, rnd), New Card(True, rnd), New Card(True, rnd)}), ({New Card(True, rnd), New Card(True, rnd), New Card(True, rnd)})}
    System.Diagnostics.Debug.WriteLine(Me.itmCurrentSets.ItemsSource.GetType().ToString())

    The first line creates a Card()() that I want to assign to Me.itmCurrentSets.ItemsSource The second line outputs the type generated by that statement, which is Card()(). The third line (which is commented out) shows the statement I would use to do that assignment. The fourth line assigns a literal Card()() to Me.itmCurrentSets.ItemsSource, as confirmed by the debug statement on line five. Here is the output when I run this code:

    SetGameUnivAppTest_Common.Card[][]
    SetGameUnivAppTest_Common.Card[][]

    This shows that both lines 1 and 4 create the same type, and it works when I use the literal (as I do in the code above), but if I attempt to use the statement on line 3 (the one that is currently commented out) it send me to the App.g.i.vb file, and points to the Break() statement in the following code:

    #If Debug AndAlso Not DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION Then
            AddHandler Me.UnhandledException,
                Sub(sender As Global.System.Object, unhandledExceptionArgs As Global.Windows.UI.Xaml.UnhandledExceptionEventArgs)
                    If Global.System.Diagnostics.Debugger.IsAttached Then
                        Global.System.Diagnostics.Debugger.Break()
                    End If
                End Sub
    #End If
    Why is one value working and another value of the same type not working? I have looked at their data, and they are both valid (no null variables, invalid values, etc.). Visual Studio 2013 does not give me an error, it just stops execution and points to the line above. I have tried deleting the App.g.i.vb file so it could be regenerated, but this did not help. What is the problem, or where or how can I get more information on what the problem is? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Saturday, October 25, 2014 3:41 AM

Answers

  • I finally found the answer! In my LINQ, I return existing Card objects, so Visual Studio 2013 didn't like it when it tried to make them items in the ItemsControl since they were already children of other elements. To solve this problem, I added a Copy() method to my Card class that returns a new Card with the same property values. So once I modified my statement to include this method as follows (note the Copy() method near the end of the statement):
    Me.itmCurrentSets.ItemsSource = New SetFinder().FindSets(Me.wrapCards.Children.Cast(Of Card).ToList()).Select(Function(s) s.Select(Function(c) CType(Me.wrapCards.Children(c), Card).Copy()).ToArray()).ToArray()
    So now it works!

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Sunday, October 26, 2014 5:43 PM

All replies

  • What is the exception?

    Does it crash when you set the ItemsSource to the commented out line or after?

    If you examine the temp array's contents does it all look reasonable? I'm guessing that something there didn't end up as you expect and need.

    You can go to the Debug.Exceptions... dialog to set the debugger to break when the exception is thrown rather than letting it get to the UnhandledException handler.

    If you need more specific help please share a minimal repro sample that demonstrates the problem.

    --Rob

    Saturday, October 25, 2014 4:05 AM
    Owner
  • I don't know what the exception is, because it does not tell me, it just shows me the code in App.g.i.vb as mentioned in my original post. If crash is the right word (since it basically closes the app in the emulator), then yes, that is what it does crash when I use the commented out line. I have examined the temp array's contents, and it all looks reasonable. I tried changing the Debug Exceptions as you suggested as follows:

    (This is what you meant, isn't it?) But it didn't seem to make any difference, it still sent me to the same place, even after I deleted the files to be regenerated. I have uploaded the two involved projects. I think I removed all the code that uses other projects, but if I didn't, any references to PhoneAppExtras or UniversalAppExtras can be removed. The link is:

    https://onedrive.live.com/redir?resid=A530643E44E725C3!32231&authkey=!AGH4agxuRp9JYIc&ithint=folder%2c

    Thank you.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Saturday, October 25, 2014 4:37 PM
  • I finally found the answer! In my LINQ, I return existing Card objects, so Visual Studio 2013 didn't like it when it tried to make them items in the ItemsControl since they were already children of other elements. To solve this problem, I added a Copy() method to my Card class that returns a new Card with the same property values. So once I modified my statement to include this method as follows (note the Copy() method near the end of the statement):
    Me.itmCurrentSets.ItemsSource = New SetFinder().FindSets(Me.wrapCards.Children.Cast(Of Card).ToList()).Select(Function(s) s.Select(Function(c) CType(Me.wrapCards.Children(c), Card).Copy()).ToArray()).ToArray()
    So now it works!

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Sunday, October 26, 2014 5:43 PM