IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Une exception non gérée du type 'System.StackOverflowException' s'est produite dans mscorlib.dll


Sujet :

VB.NET

  1. #1
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2012
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 640
    Points : 372
    Points
    372
    Par défaut Une exception non gérée du type 'System.StackOverflowException' s'est produite dans mscorlib.dll
    Bonjour,
    J'ai une classe héritée de TraceSource pour personnaliser les messages. Celle-ci a toujours fonctionné très bien sauf que cette fois j'emet des messages également depuis un Thread secondaire et au bout d'un moment j'ai cette erreur. Et je ne sais pas comment régler le problème afin que ma classe puisse fonctionner depuis n'importe quel Thread.

    PS : La procédure ControlFileSize permets d'effacer le fichier de trace si celui-ci dépasse une certaine taille. En même temps je me pose la question de savoir si j'ai bien fait d'implémenter cette fonction et si il n'existe pas déjà cette fonction dans la classe d'origine mais je n'ai pas trouvé.

    J'ai mis un extrait de ma classe ci-dessous, si besoin je peux fournir la classe complète.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    Public Class clsTraceSource
        Inherits TraceSource
     Public Overloads Sub TraceEvent(eventType As System.Diagnostics.TraceEventType, id As Integer, message As String)
            Call _TraceEvent(eventType, id, message, ProfilTrace.Defaut)
        End Sub
        Public Overloads Sub TraceEvent(eventType As System.Diagnostics.TraceEventType, id As Integer, message As String, profil As ProfilTrace)
            Call _TraceEvent(eventType, id, message, profil)
        End Sub
        Private Sub _TraceEvent(eventType As System.Diagnostics.TraceEventType, id As Integer, message As String, _
                                        profil As ProfilTrace)
      .....
              If eventType <= Me.Switch.Level Then
                For Each _listener As TraceListener In Me.Listeners
                    If _listener.GetType Is GetType(TextWriterTraceListener) Then
                        Dim strFilePath = FilePath(_listener)
                        Call ControlFileSize(strFilePath)
                    End If
     
                    Dim msg As String = ""
    .....
                    msg = arg(0) & arg(1) & arg(2) & Convert.ToChar(Keys.Tab) & arg(9) & arg(10) & message
     
                    _listener.WriteLine(msg)
                    _listener.Flush()
                Next
            End If
        End Sub
     
      Private Sub ControlFileSize(ByVal filepath As String)
            Try
                Dim Fi = New System.IO.FileInfo(filepath)   ' Cette ligne provoque une exception
                If Fi.Exists And Fi.Length > _twfileSize Then
                    Me.Close()
                    Fi.Delete()
                End If
            Catch ex As Exception
            End Try
        End Sub
    End Class
    J'aimerais beaucoup que vous puissiez m'aider, j'ai presque fini mon programme et j'aimerais bien faire fonctionner ma classe.

  2. #2
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2012
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 640
    Points : 372
    Points
    372
    Par défaut
    Bonsoir, c'est bien l’accès inter-Threads qui pose un problème a ma classe, j'ai d'ailleurs une autre exception avec un composant "Stopwatch".
    je suis complètement depassé par ces problèmes de Threads et si quelqu'un veux bien m'aider ca serait super sympa.

    Voici ma classe complète :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    Public Enum ProfilTrace
        Defaut
        'None
        'All
        StartChrono
        StopChrono
    End Enum
    Public Class clsTraceSource
        Inherits TraceSource
        Private _twfileSize As Integer = 100000 ' Taille des fichiers TextWriterTraceListener par défaut = 100ko
        Dim _Chronos As New System.Collections.Generic.Dictionary(Of String, Stopwatch)
        Dim _IDChronos As New System.Collections.Generic.Dictionary(Of String, Integer)
        Dim _Compteur As Integer = 0
        'Dim _TraceOptionalOutPutOptions As Boolean
        'Dim Stopwatch As System.Diagnostics.Stopwatch
        Public Sub New(ByVal name As String)
            MyBase.New(name)
        End Sub
     
        Public Property TextWriterFileSize() As Integer
            Get
                Return _twfileSize
            End Get
            Set(ByVal value As Integer)
                _twfileSize = value
            End Set
        End Property
        'Public Property TraceOptionalOutPutOptions() As Boolean
        '    Get
        '        Return _TraceOptionalOutPutOptions
        '    End Get
        '    Set(ByVal value As Boolean)
        '        _TraceOptionalOutPutOptions = value
        '    End Set
        'End Property
        Public Sub WriteAppInfos()
            Dim strProductName = My.Application.Info.ProductName
            Dim strVersion = String.Format("Version {0}", My.Application.Info.Version.ToString)
            Dim strCopyright = My.Application.Info.Copyright
            Dim strCompanyName = My.Application.Info.CompanyName
            Dim strDescription = My.Application.Info.Description
            Dim strToday As String = "Date : " & DateTime.Now.ToShortDateString
     
            Dim strCompilMode As String = "Mode Compilation=Release"
     
    #If Debug = True Then 'Code executé uniquement en mode Debug
            strCompilMode = "Mode Compilation=Debug"
    #End If
            Dim message As String
            message = strProductName & " - " & strVersion & Environment.NewLine & strCompilMode & Environment.NewLine & strToday
     
            For Each _listener As TraceListener In Me.Listeners
                _listener.WriteLine(message)
                _listener.Flush()
            Next
        End Sub
        Public Sub WriteTraceInfos()
     
            Dim message As String = String.Format("---Le Logger {0} est démarré avec TraceSwitchLevel = {1}---", Me.Name, Me.Switch.Level.ToString)
     
            For Each _listener As TraceListener In Me.Listeners
                _listener.WriteLine(message)
                _listener.Flush()
            Next
        End Sub
        Public Overloads Sub TraceEvent(eventType As System.Diagnostics.TraceEventType, id As Integer, message As String)
            Call _TraceEvent(eventType, id, message, ProfilTrace.Defaut)
        End Sub
        Public Overloads Sub TraceEvent(eventType As System.Diagnostics.TraceEventType, id As Integer, message As String, profil As ProfilTrace)
            Call _TraceEvent(eventType, id, message, profil)
        End Sub
        Private Sub _TraceEvent(eventType As System.Diagnostics.TraceEventType, id As Integer, message As String, _
                                        profil As ProfilTrace)
            Dim val(11) As String ' = {"A", "B"}
            Dim pref(11) As String ' = {"Date = ", "Time = "}
            Dim arg(11) As String
     
            Static i As Integer : i += 1
            arg(6) = "[" & i.ToString & "]"
            arg(7) = Convert.ToChar(Keys.Tab) & DateTime.Now.ToLongTimeString & " " & DateTime.Now.Millisecond
     
            arg(9) = Convert.ToChar(Keys.Tab) & "-" & [Enum].GetName(GetType(TraceEventType), eventType) & "-"
            If eventType = TraceEventType.Error Then
                arg(9) = arg(9).ToUpper ' si TraceLevel = TraceError on affiche TraceLevel en Majuscule
                message = arg(9) & ":" & message ' si TraceLevel = TraceError on rajoute ERROR: devant le libellé
            End If
     
            Dim strSubCurrent As String = ""
            Dim strModuleParent As String = ""
            Dim strSubModule As String = ""
     
            Dim stTraceFrame As StackFrame = New StackFrame(2)
            Dim methode As System.Reflection.MethodBase = stTraceFrame.GetMethod
     
            strSubCurrent = methode.Name
            strModuleParent = methode.DeclaringType.FullName
            Dim SubFullName As String = strModuleParent & "/" & strSubCurrent
            arg(10) = Convert.ToChar(Keys.Tab) & " [" & strModuleParent & "/" & Convert.ToChar(Keys.Tab) & strSubCurrent & "]"
     
            message = Convert.ToChar(Keys.Tab) & " => " & message
     
            If eventType <= Me.Switch.Level Then
                For Each _listener As TraceListener In Me.Listeners
                    If _listener.GetType Is GetType(TextWriterTraceListener) Then
                        'Dim strFilePath = FilePath(_listener)
                        'Call ControlFileSize(strFilePath)
                        Call ControlFileSize2(CType(_listener, TextWriterTraceListener))
                    End If
                    For n = 0 To 5
                        val(n) = "" : pref(n) = "" : arg(n) = ""
                    Next
                    Dim op As TraceOptions = _listener.TraceOutputOptions
                    Dim eventcache As New TraceEventCache
                    'If a.HasFlag(TraceOptions.None) Then Beep()
                    If op.HasFlag(TraceOptions.LogicalOperationStack) Then pref(0) = " - LogicalOperationStack = " : val(0) = eventcache.LogicalOperationStack.ToString : arg(0) = Convert.ToChar(Keys.Tab) & pref(0) & val(0)
                    If op.HasFlag(TraceOptions.DateTime) Then pref(1) = " - DateTime = " : val(1) = CStr(eventcache.DateTime) : arg(1) = Convert.ToChar(Keys.Tab) & pref(1) & val(1)
                    If op.HasFlag(TraceOptions.Timestamp) Then pref(2) = " - Timestamp = " : val(2) = CStr(eventcache.Timestamp) : arg(2) = Convert.ToChar(Keys.Tab) & pref(2) & val(2)
                    If op.HasFlag(TraceOptions.ProcessId) Then pref(3) = " - ProcessId = " : val(3) = CStr(eventcache.ProcessId) : arg(3) = Convert.ToChar(Keys.Tab) & pref(3) & val(3)
                    If op.HasFlag(TraceOptions.ThreadId) Then pref(4) = " - ThreadId = " : val(4) = CStr(eventcache.ProcessId) : arg(4) = Convert.ToChar(Keys.Tab) & pref(4) & val(4)
                    If op.HasFlag(TraceOptions.Callstack) Then pref(5) = " - Callstack = " : val(5) = eventcache.Callstack : arg(5) = Convert.ToChar(Keys.Tab) & pref(5) & val(5)
     
                    'Dim strProfil As String = ""
                    'If showId = False Then arg(7) = ""
                    'If showTime = False Then arg(8) = ""
                    'If showEventType = False Then arg(9) = ""
                    'If showEventType = False Then arg(10) = ""
                    If eventType <= TraceEventType.Warning Or eventType >= TraceEventType.Verbose Then
                        arg(8) = Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab)
                    Else
                        arg(8) = Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) : arg(10) = ""
                    End If
                    Select Case profil
                        'Case ProfilTrace.None
                        '    arg(6) = "" : arg(7) = "" : arg(8) = Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) : arg(9) = "" : arg(10) = ""
                        'Case ProfilTrace.Standard
                        '    arg(8) = Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) : arg(10) = ""
                        'Case ProfilTrace.All
                        '    arg(8) = Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab) & Convert.ToChar(Keys.Tab)
                        Case ProfilTrace.StartChrono
                            Call StartChrono(SubFullName)
                            arg(8) = Convert.ToChar(Keys.Tab) & "[Chrono" & GetIdChrono(SubFullName) & ":Start]"
                        Case ProfilTrace.StopChrono
                            arg(8) = Convert.ToChar(Keys.Tab) & "[Chrono" & GetIdChrono(SubFullName) & ":" & Math.Round(StopChrono(SubFullName), 2).ToString & "ms]"
                    End Select
                    Dim msg As String = ""
                    'If Me.TraceOptionalOutPutOptions = True Then
                    msg = arg(6) & arg(7) & arg(8) & Convert.ToChar(Keys.Tab) & arg(9) & arg(0) & arg(1) & arg(2) & arg(3) & arg(4) & arg(5) & arg(10) & message
                    'Else
                    'msg = arg(6) & arg(7) & arg(8) & Convert.ToChar(Keys.Tab) & arg(9) & arg(10) & message
                    'End If
     
                    _listener.WriteLine(msg)
                    '_listener.Flush()
                Next
            End If
        End Sub
        Private Sub ControlFileSize2(ByVal listener As TextWriterTraceListener)
            Dim tw As TextWriterTraceListener = CType(listener, TextWriterTraceListener)
            Dim sw As System.IO.StreamWriter = CType(tw.Writer, IO.StreamWriter)
            Dim bs As System.IO.FileStream = CType(sw.BaseStream, IO.FileStream)
            Dim _filepath = bs.Name
     
            Try
                Dim Fi = New System.IO.FileInfo(_filepath)
                If Fi.Exists And Fi.Length > _twfileSize Then
                    Me.Close()
                    Fi.Delete()
                End If
                Fi = Nothing
            Catch ex As Exception
            End Try
        End Sub
        'Private Function FilePath(ByVal listener As TraceListener) As String
        '    'Dim finfo As System.Reflection.FieldInfo = listener.GetType.GetField("initializeData", Reflection.BindingFlags.NonPublic + Reflection.BindingFlags.Instance)
        '    'Dim filename As String = finfo.GetValue(listener)
     
        '    Dim tw As TextWriterTraceListener = CType(listener, TextWriterTraceListener)
        '    Dim sw As System.IO.StreamWriter = CType(tw.Writer, IO.StreamWriter)
        '    Dim bs As System.IO.FileStream = CType(sw.BaseStream, IO.FileStream)
        '    Dim _filepath = bs.Name
        '    Return _filepath
        'End Function
        'Private Sub ControlFileSize(ByVal filepath As String)
        '    Try
        '        Dim Fi = New System.IO.FileInfo(filepath)
        '        If Fi.Exists And Fi.Length > _twfileSize Then
        '            Me.Close()
        '            Fi.Delete()
        '        End If
        '        Fi = Nothing
        '    Catch ex As Exception
        '    End Try
        'End Sub
        Private Function GetIdChrono(ByVal name As String) As Integer
            If _IDChronos.ContainsKey(name) Then
                Return _IDChronos(name)
            Else
                Return -1
            End If
        End Function
        Private Sub StartChrono(ByVal name As String)
            If _Chronos.ContainsKey(name) Then
                _Chronos(name).Reset()
            Else
                _Chronos.Add(name, New Stopwatch)
                _IDChronos.Add(name, _Compteur)
                _Compteur += 1
            End If
            _Chronos(name).Start()
        End Sub
        Private Function StopChrono(ByVal name As String) As Double
            Dim Value As Double
            If _Chronos.ContainsKey(name) Then
                _Chronos(name).Stop()
                Value = _Chronos(name).Elapsed.TotalMilliseconds
            Else
                '_Chronos.Add("tel nom", New Stopwatch)
            End If
            Return Value
        End Function
        'Private Sub Watching(ByVal Value As String)
        '    If Value = "Start" Then
        '        ' Initialisation : debut de la mesure
        '        Stopwatch.Start()
        '    ElseIf Value = "Stop" Then
        '        ' fin de la mesure
        '        Stopwatch.Stop()
     
        '        ' Affichage de la mesure
        '        Console.WriteLine(Stopwatch.Elapsed().TotalMilliseconds & " millisecondes")
        '        Console.ReadKey()
        '        'MessageBox.Show(Stopwatch.Elapsed().TotalSeconds & " secondes")
        '    End If
        'End Sub
    End Class

  3. #3
    Membre averti
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mars 2012
    Messages
    640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Bâtiment

    Informations forums :
    Inscription : Mars 2012
    Messages : 640
    Points : 372
    Points
    372
    Par défaut
    Bonjour, je crois que j'ai trouvé l'origine du problème. C'est du a une architecture de mon programme un peu bancale mais a l'époque je ne savais pas faire mieux. Maintenant que mon programme contient 30000 lignes de codes je ne vais pas y toucher aujourd'hui .
    En effet, Je fait des écritures dans un DataTable a l’intérieur de l'événement DataTable.ColumnChanging. A l'époque j'avais pris soin de désactiver l’événement a chaque fois que je rentre a l’intérieur de ColumnChanging mais depuis que j'ai implémenté une nouvelle fonction lancé par un BackGroundWorker cet événement ne se désactive plus ce qui entraîne des appels récursifs de l’événement ColumnChanging et fini par un stackOverFlowException. Cela lance même une nouvelle instance de mes formulaires alors qu'il sont déjà construits.

    Bref, en attendant d'avoir de meilleures connaissances en ADO.NET je lancé ma nouvelle fonction dans le Thread Principal et tout est rentré dans l'ordre.
    Je marque en résolu bien que le problème ne soit pas complément résolu, je ferais peut-être un autre post dans la rubrique ADO.NET a moins que quelqu'un apporte une réponse ici.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 0
    Dernier message: 26/08/2014, 20h03
  2. Réponses: 2
    Dernier message: 30/05/2014, 14h45
  3. Réponses: 0
    Dernier message: 30/05/2014, 10h54
  4. Réponses: 0
    Dernier message: 21/03/2014, 20h02
  5. Réponses: 2
    Dernier message: 09/07/2007, 11h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo