Microsoft Developer Network > Página Inicial dos Fóruns > .NET Base Class Library > Stack overflow from apparent infinite loop in Settings.Designer.vb
Fazer uma PerguntaFazer uma Pergunta
 

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

  • quarta-feira, 4 de novembro de 2009 18:10bienvenunet Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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.

Respostas

Todas as Respostas

  • quarta-feira, 4 de novembro de 2009 18:28Reed Copsey, Jr. Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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
  • quinta-feira, 5 de novembro de 2009 0:51bienvenunet Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    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.
  • quinta-feira, 5 de novembro de 2009 5:24MSFT Johan StenbergModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    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