Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Setting Tag value on Button to Canvas causes System.StackOverflowException in Silverlight 2.0 B2
5 replies. Latest Post by avbersSL on August 26, 2008.
(0)
dbaechtel
Member
59 points
207 Posts
08-22-2008 10:39 AM |
I have the following code inside a MouseLeftButtonUp event Handler routine inside a UserControl: bCanvas = New Canvas bCanvas.Tag = Me mainCanvas.Children.Add(bCanvas) Dim s3 As New StackPanel s3.Orientation = Orientation.Horizontal Canvas.SetTop(s3, 90) Canvas.SetLeft(s3, 90) Dim HL As New Button Dim HLtext As New TextBlock HLtext.Text = "Edit details" HL.Content = HLtext HL.Tag = bCanvas HL.Margin = New Thickness(20, 0, 0, 0) s3.Children.Add(HL) bCanvas.Children.Add(s3) bCanvas.Visibility = Windows.Visibility.Visible As soon as I single Step the Add(s3) line I get the StackOverflow after a few seconds.If I comment out the "HL.Tag = bCanvas" line, it runs OK.if I put the HL.Tag line in again, the exception occurs again. This code runs fine in a WPF application, but gets the Exception in SL 2.0 B2. Why does setting a Tag value on a Button to reference a Canvas cause a StackOverflowException ?How do I fix this?
bCanvas = New Canvas bCanvas.Tag = Me mainCanvas.Children.Add(bCanvas) Dim s3 As New StackPanel s3.Orientation = Orientation.Horizontal Canvas.SetTop(s3, 90) Canvas.SetLeft(s3, 90) Dim HL As New Button Dim HLtext As New TextBlock HLtext.Text = "Edit details" HL.Content = HLtext HL.Tag = bCanvas HL.Margin = New Thickness(20, 0, 0, 0) s3.Children.Add(HL) bCanvas.Children.Add(s3) bCanvas.Visibility = Windows.Visibility.Visible
As soon as I single Step the Add(s3) line I get the StackOverflow after a few seconds.If I comment out the "HL.Tag = bCanvas" line, it runs OK.if I put the HL.Tag line in again, the exception occurs again.
This code runs fine in a WPF application, but gets the Exception in SL 2.0 B2.
Why does setting a Tag value on a Button to reference a Canvas cause a StackOverflowException ?How do I fix this?
pbromberg
Contributor
2128 points
370 Posts
08-25-2008 9:01 PM |
When you get a StackOverflow exception, it almost always means that you have inadvertently caused an infinite recursive loop, through some coding error. Set a breakpoint in your code to trace how you may be causing this to happen. Your code sample is not complete, so its difficult to tell where the error may lie.
The fact that the code may run OK in WPF is not relevant. Silverlight != WPF in many cases.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
08-26-2008 12:11 AM |
Hello, thanks for reporting this issue. I've tested it in Beta2, and I did get a stack overflow. But when I tested it in an internal RTW build, it worked fine. So hopefully this issue has already been solved. But I can't 100% assure you at this time...
08-26-2008 7:37 AM |
The StackTrace shows that it is not looping in my code, but in MS internal code only.
Since I get a Stack Overflow when I Single Step just one line of my code shows that the recursive loop is not in my code.
08-26-2008 7:39 AM |
MS had better make sure that this problem is fixed before the next release of Silverlight.
Since the VSTS 2008 error messages do not give the location in my code where the problem begins, it is very difficult to find and not obvious.
avbersSL
164 points
78 Posts
08-26-2008 10:00 AM |
RTW build?
I hope there will be another Beta / RC before actual release...?