.NET Framework Developer Center > .NET Development Forums > .NET Base Class Library > Stack overflow from apparent infinite loop in Settings.Designer.vb
Ask a questionAsk a question
 

AnswerStack overflow from apparent infinite loop in Settings.Designer.vb

  • Wednesday, November 04, 2009 6:10 PMbienvenunet Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have an application that is going into an apparent infinite loop while setting up Settings, before the main window even loads. 

    The error occurs in the Default method of MySettings, on the AddHandler statement. 

            Public Shared ReadOnly Property [Default]() As MySettings
                Get
                    
    #If _MyType = "WindowsForms" Then
                   If Not addedHandler Then
                        SyncLock addedHandlerLockObject
                            If Not addedHandler Then
                                AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
                                addedHandler = True
                            End If
                        End SyncLock
                    End If
    #End If
                    Return defaultInstance
                End Get
            End Property

    The exception thrown is StackOverflowException, which clearly points to an infinite loop.

    What is causing this? This is in Visual Studio 2008 Express, using .Net 3.5. I have not modified the above code nor do I intend to.

Answers

All Replies

  • Wednesday, November 04, 2009 6:28 PMReed Copsey, Jr. Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'd guess that this isn't the actual problematic line, but rather the line where you overflow your stack.

    Try opening up the call stack window in the debugger when this occurs, and seeing what is accessing MySettings.  My guess is that you're trying to access your settings for a property initialization routine somewhere, but calling it incorrectly, and causing the infinite loop.
    Reed Copsey, Jr. - http://reedcopsey.com
  • Thursday, November 05, 2009 12:51 AMbienvenunet Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The call stack isn't helpful. I put a breakpoint on the bolded line and the first time it breaks, the only thing under the Default property in the stack is External Code.
  • Thursday, November 05, 2009 5:24 AMMSFT Johan StenbergModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    From http://msdn.microsoft.com/en-us/library/a3694ts5.aspx:

     To display non-user code frames in the Call Stack window

       Right-click the Call Stack window and choose Show External Code

    This will hopefully give you a better idea as to what is going on...

    Best regards,
    Johan Stenberg


    Microsoft Visual Studio