none
Substring方法引发的0xc0000005错误,微软请告诉我哪里错了,还是你错了 RRS feed

  • 问题

  • 调试程序错误提示:托管调试助手 "FatalExecutionEngineError":“运行时遇到了错误。此错误的地址为 0xe291ae61,在线程 0x22ad0 上。错误代码为 0xc0000005。此错误可能是 CLR 中的 bug,或者是用户代码的不安全部分或不可验证部分中的 bug。此 bug 的常见来源包括用户对 COM-interop 或 PInvoke 的封送处理错误,这些错误可能会损坏堆栈。”

    如果该错误发生在发布后的(EXE)项目中,肯定不可捕获,并导致程序关闭。代码如下,很简单,请告诉我哪里错了。

    Dim i As Integer
                            For i = Len(tempfurl) To 1 Step -1
                                If tempfurl.Substring(i - 1, 1) = "/" Then ‘此行提示上述不可捕获错误
                                    temp = tempfurl.Substring(0, i) & temp
                                    Exit For
                                End If
                            Next

    局部变量如下:

    tempfurl="http:||s.weibo.com/weibo/%25E6%2596%25BD%25E7%2594%25B8&nodup=1&timescope=custom:2017-11-29-9:2017-11-29-10"

    i=47

    补充:以上代码在多线程下运行,次错误应为偶发,但必然导致exe关闭,这又何垃圾回收有关系?我在出错代码前一行加上下方代码有意义吗?不得已为之

    Dim i As Integer
                            For i = Len(tempfurl) To 1 Step -1
                                If IsNothing(tempfurl) = True OrElse Len(tempfurl) < i Then Exit For '加上这句有意义吗,不得已为之
                                If tempfurl.Substring(i - 1, 1) = "/" Then 
                                    temp = tempfurl.Substring(0, i) & temp
                                    Exit For
                                End If
                            Next





    • 已编辑 shusir 2017年11月29日 14:33
    2017年11月29日 14:09

全部回复

  • Hi shusir,

    我已经尝试了你的代码, 并且把它放在多线程里面进行测试, 我遇到任何问题。

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim mythread1 As Thread
            Dim mythread2 As Thread
            Dim mythread3 As Thread
            '创建线程对象  
            mythread1 = New Thread(AddressOf mythreadrun)
            mythread2 = New Thread(AddressOf mythreadrun1)
            mythread3 = New Thread(AddressOf mythreadrun2)
            Console.WriteLine(Now.ToLongTimeString & "线程对象创建完毕,开始执行线程")
            '执行线程  
            mythread1.Start("线程1")
            mythread2.Start("线程2")
            mythread3.Start("线程3")
            '等待线程完成  
            mythread1.Join()
            mythread2.Join()
            mythread3.Join()
            '线程执行完毕  
            Console.WriteLine(Now.ToLongTimeString & "线程执行完毕!")
            Console.ReadLine()
        End Sub
        Public Sub mythreadrun(ByVal data As Object)
            Dim tempfurl = "http:||s.weibo.com/weibo/%25E6%2596%25BD%25E7%2594%25B8&nodup=1&timescope=custom:2017-11-29-9:2017-11-29-10"
            Dim i As Integer
            Dim temp As String = ""
            For i = Len(tempfurl) - 1 To 1 Step -1
                If tempfurl.Substring(i - 1, 1) = "/" Then '此行提示上述不可捕获错误
                    temp = tempfurl.Substring(0, i) & temp
                    MessageBox.Show(temp)
                    Exit For
                End If
            Next
        End Sub
        Public Sub mythreadrun1(ByVal data As Object)
            Console.WriteLine("B")
            Console.ReadLine()
        End Sub
        Public Sub mythreadrun2(ByVal data As Object)
            Console.WriteLine("C")
            Console.ReadLine()
        End Sub

    请你再次尝试着运行你的代码, 看看是否还是在那一行出现问题, 如果是的话, 那可能您把你的整个项目或者多分享一点代码在这里。

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2017年11月30日 7:24