Skip to main content

Microsoft Silverlight

Unanswered Question Setting Tag value on Button to Canvas causes System.StackOverflowException in Silverlight 2.0 B2RSS Feed

(0)

dbaechtel
dbaechtel

Member

Member

59 points

207 Posts

Setting Tag value on Button to Canvas causes System.StackOverflowException in Silverlight 2.0 B2

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?

pbromberg
pbromberg

Contributor

Contributor

2128 points

370 Posts

Re: Setting Tag value on Button to Canvas causes System.StackOverflowException in Silverlight 2.0 B2

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 Luo - MSFT
Yi-Lun L...

All-Star

All-Star

25052 points

2,747 Posts

Re: Setting Tag value on Button to Canvas causes System.StackOverflowException in Silverlight 2.0 B2

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...

shanaolanxing - I'll transfer to the Windows Azure team, and will have limited time to participate in the Silverlight forum. Apologize if I don't answer your questions in time.

dbaechtel
dbaechtel

Member

Member

59 points

207 Posts

Re: Setting Tag value on Button to Canvas causes System.StackOverflowException in Silverlight 2.0 B2

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.

 

 

dbaechtel
dbaechtel

Member

Member

59 points

207 Posts

Re: Setting Tag value on Button to Canvas causes System.StackOverflowException in Silverlight 2.0 B2

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
avbersSL

Member

Member

164 points

78 Posts

RTW Build?

RTW build?

I hope there will be another Beta / RC before actual release...?

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities