Results 1 to 12 of 12

Thread: "The call stack contains only external code" error

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    12

    "The call stack contains only external code" error

    Can someone help me out here? Things were running smoothly but suddenly, the debugging stops then it leads me here -> Name:  a.jpg
Views: 192
Size:  18.4 KB

    What's worse is I tried to do the entire design and code again in a new project thinking that that problem only appears in that one specific project. Wasted about two hours. I'm putting my entire code here in case the problem lies somewhere in my code, this will be long but please help me out. I may have missed something.

    Code:
    Imports System.Drawing.Text
        Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
            Dim pfc As PrivateFontCollection = New PrivateFontCollection
            pfc.AddFontFile("digital-7 (italic).ttf")
            Label2.Font = New Font(pfc.Families(0), 30, FontStyle.Regular)
            Label2.ForeColor = Color.Black
            Dim pfc2 As PrivateFontCollection = New PrivateFontCollection
            pfc2.AddFontFile("digital-7.ttf")
            Label1.Font = New Font(pfc2.Families(0), 26, FontStyle.Regular)
            Label1.ForeColor = Color.Black
            BtnCase.Hide()
            BtnVer.Hide()
            BtnOff.Hide()
            BtnOn.Hide()
            BtnExp.Hide()
            BtnCube.Hide()
            BtnFact.Hide()
            BtnSqrt.Hide()
            Num7.Hide()
            Num8.Hide()
            Num9.Hide()
            BtnDel.Hide()
            BtnAC.Hide()
            Num4.Hide()
            Num5.Hide()
            Num6.Hide()
            BtnMult.Hide()
            BtnDiv.Hide()
            Num1.Hide()
            Num2.Hide()
            Num3.Hide()
            BtnAdd.Hide()
            BtnSub.Hide()
            Num0.Hide()
            BtnPi.Hide()
            BtnSqrd.Hide()
            BtnDot.Hide()
            BtnEql.Hide()
            BtnUp.Hide()
            BtnDown.Hide()
            BtnLeft.Hide()
            BtnRight.Hide()
        End Sub
    
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Label2.Text = ""
            Timer1.Enabled = False
        End Sub
    
        Private Sub ButtonClickMethod(sender As Object, e As EventArgs) Handles BtnCase.Click, BtnVer.Click, BtnOff.Click, BtnOn.Click, BtnExp.Click, BtnCube.Click, BtnFact.Click, BtnSqrt.Click, Num7.Click, Num8.Click, Num9.Click, BtnDel.Click, BtnAC.Click, Num4.Click, Num5.Click, Num6.Click, BtnMult.Click, BtnDiv.Click, Num1.Click, Num2.Click, Num3.Click, BtnAdd.Click, BtnSub.Click, Num0.Click, BtnPi.Click, BtnSqrd.Click, BtnDot.Click, BtnEql.Click, BtnUp.Click, BtnDown.Click, BtnLeft.Click, BtnRight.Click
            Dim btn As Button = CType(sender, Button)
    
            If btn.Name = "BtnCase" Then
                Timer2.Enabled = True
                BtnCase.Hide()
                BtnVer.Hide()
                BtnOff.Hide()
                BtnOn.Hide()
                BtnExp.Hide()
                BtnCube.Hide()
                BtnFact.Hide()
                BtnSqrt.Hide()
                Num7.Hide()
                Num8.Hide()
                Num9.Hide()
                BtnDel.Hide()
                BtnAC.Hide()
                Num4.Hide()
                Num5.Hide()
                Num6.Hide()
                BtnMult.Hide()
                BtnDiv.Hide()
                Num1.Hide()
                Num2.Hide()
                Num3.Hide()
                BtnAdd.Hide()
                BtnSub.Hide()
                Num0.Hide()
                BtnPi.Hide()
                BtnSqrd.Hide()
                BtnDot.Hide()
                BtnEql.Hide()
                BtnUp.Hide()
                BtnDown.Hide()
                BtnLeft.Hide()
                BtnRight.Hide()
            End If
    
            If btn.Name = "BtnVer" Then
                Label1.Text = ""
                Label2.Text = "WE BARE BEARS"
            End If
    
            If btn.Name = "BtnOff" Then
                Label1.Text = ""
                Label2.Text = "CASEO"
                Timer1.Enabled = True
                BtnVer.Hide()
                BtnOff.Hide()
                BtnExp.Hide()
                BtnCube.Hide()
                BtnFact.Hide()
                BtnSqrt.Hide()
                Num7.Hide()
                Num8.Hide()
                Num9.Hide()
                BtnDel.Hide()
                BtnAC.Hide()
                Num4.Hide()
                Num5.Hide()
                Num6.Hide()
                BtnMult.Hide()
                BtnDiv.Hide()
                Num1.Hide()
                Num2.Hide()
                Num3.Hide()
                BtnAdd.Hide()
                BtnSub.Hide()
                Num0.Hide()
                BtnPi.Hide()
                BtnSqrd.Hide()
                BtnDot.Hide()
                BtnEql.Hide()
                BtnUp.Hide()
                BtnDown.Hide()
                BtnLeft.Hide()
                BtnRight.Hide()
            End If
    
            If btn.Name = "BtnOn" Then
                Label1.Text = ""
                Label2.Text = 0
                BtnVer.Show()
                BtnOff.Show()
                BtnExp.Show()
                BtnCube.Show()
                BtnFact.Show()
                BtnSqrt.Show()
                Num7.Show()
                Num8.Show()
                Num9.Show()
                BtnDel.Show()
                BtnAC.Show()
                Num4.Show()
                Num5.Show()
                Num6.Show()
                BtnMult.Show()
                BtnDiv.Show()
                Num1.Show()
                Num2.Show()
                Num3.Show()
                BtnAdd.Show()
                BtnSub.Show()
                Num0.Show()
                BtnPi.Show()
                BtnSqrd.Show()
                BtnDot.Show()
                BtnEql.Show()
                BtnUp.Show()
                BtnDown.Show()
                BtnLeft.Show()
                BtnRight.Show()
            End If
    
            If btn.Name = "BtnExp" Then
                Label1.Text = Label1.Text + "^"
            End If
    
            If btn.Name = "BtnCube" Then
                Label1.Text = Label1.Text + "^3"
            End If
    
            If btn.Name = "BtnFact" Then
                Label1.Text = Label1.Text + "!"
            End If
    
            If btn.Name = "BtnSqrt" Then
                Label1.Text = Label1.Text + "√"
            End If
    
            If btn.Name = "Num7" Then
                Label1.Text = Label1.Text + "7"
            End If
    
            If btn.Name = "Num8" Then
                Label1.Text = Label1.Text + "8"
            End If
    
            If btn.Name = "Num9" Then
                Label1.Text = Label1.Text + "9"
            End If
    
            If btn.Name = "BtnDel" Then
                ' Label1.Text = Label1.Text + "="
            End If
    
            If btn.Name = "BtnAC" Then
                ' Label1.Text = Label1.Text + "="
            End If
    
            If btn.Name = "Num4" Then
                Label1.Text = Label1.Text + "4"
            End If
    
            If btn.Name = "Num5" Then
                Label1.Text = Label1.Text + "5"
            End If
    
            If btn.Name = "Num6" Then
                Label1.Text = Label1.Text + "6"
            End If
    
            If btn.Name = "BtnMult" Then
                Label1.Text = Label1.Text + ""
            End If
    
            If btn.Name = "BtnDiv" Then
                Label1.Text = Label1.Text + ""
            End If
    
            If btn.Name = "Num1" Then
                Label1.Text = Label1.Text + "1"
            End If
    
            If btn.Name = "Num2" Then
                Label1.Text = Label1.Text + "2"
            End If
    
            If btn.Name = "Num3" Then
                Label1.Text = Label1.Text + "3"
            End If
    
            If btn.Name = "BtnAdd" Then
                Label1.Text = Label1.Text + "+"
            End If
    
            If btn.Name = "BtnSub" Then
                Label1.Text = Label1.Text + "-"
            End If
    
            If btn.Name = "Num0" Then
                Label1.Text = Label1.Text + "0"
            End If
    
            If btn.Name = "BtnPi" Then
                Label1.Text = Label1.Text + "π"
            End If
    
            If btn.Name = "BtnSqrd" Then
                Label1.Text = Label1.Text + "^2"
            End If
    
            If btn.Name = "BtnDot" Then
                Label1.Text = Label1.Text + "."
            End If
    
            If btn.Name = "BtnEql" Then
                Label1.Text = Label1.Text + "="
            End If
    
            If btn.Name = "BtnUp" Then
    
            End If
    
            If btn.Name = "BtnDown" Then
    
            End If
    
            If btn.Name = "BtnLeft" Then
    
            End If
    
            If btn.Name = "BtnRight" Then
    
            End If
    
        End Sub
    
        Private Const INCREMENT As Integer = 9
        Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
            If PictureBox1.Location.Y >= 1050 Then
                Timer2.Enabled = False
                BtnCase.Show()
                BtnOn.Show()
            Else
                PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y + INCREMENT)
            End If
        End Sub
    
        Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
            Timer2.Enabled = True
        End Sub
    
        Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
            If PictureBox1.Location.Y <= 0 Then
                Timer3.Enabled = False
            Else
                PictureBox1.Location = New Point(PictureBox1.Location.X, PictureBox1.Location.Y - INCREMENT)
            End If
        End Sub
    End Class

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,746

    Re: "The call stack contains only external code" error

    For future reference, don't take a shot of your entire screen when only a tiny but of it is relevant. Windows 10 even has two tools for taking screenshots and both will let you you select a part of the screen. If you're not prepared to make a small effort like that to help us, it doesn't tend to inspire us to want to help you.

  3. #3
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,746

    Re: "The call stack contains only external code" error

    Also, there's a lot of code there but you haven't provided any indication of what was the last line you saw successfully executed. If you don't know then you haven't debugged your code, so do that first and then let us know what actually happens. When you know what line was last successfully executed, you'll hopefully know which line failed. It may still not happen within one of those methods but if we know which ones succeed and which don't then that still helps. If execution never gets into the Load event handler, that's still relevant information.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    12

    Re: "The call stack contains only external code" error

    Unfortunately, I created another project and copied the whole code from the previous project so that was the first time I debugged it. No way to know which line was last executed successfully. However, in my previous code, I vaguely remember I was doing the BtnDel when the error first happened.
    For example, I tried to input "9999" and click the BtnDel to delete each one, and when the last "9" was left, I tried to click the button again in hopes that the last "9" would get deleted as well then that happened. But take this with a grain of salt, that error may have appeared earlier than what I remember.
    After that, I tried to disable the Just My Code as instructed but enabled it again when it didn't work. I also tried checking the "Break when this exception is thrown", didn't work either.

    Quote Originally Posted by jmcilhinney View Post
    Also, there's a lot of code there but you haven't provided any indication of what was the last line you saw successfully executed. If you don't know then you haven't debugged your code, so do that first and then let us know what actually happens. When you know what line was last successfully executed, you'll hopefully know which line failed. It may still not happen within one of those methods but if we know which ones succeed and which don't then that still helps. If execution never gets into the Load event handler, that's still relevant information.

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    12

    Re: "The call stack contains only external code" error

    I'm very sorry about that.

    Quote Originally Posted by jmcilhinney View Post
    For future reference, don't take a shot of your entire screen when only a tiny but of it is relevant. Windows 10 even has two tools for taking screenshots and both will let you you select a part of the screen. If you're not prepared to make a small effort like that to help us, it doesn't tend to inspire us to want to help you.

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    12

    Re: "The call stack contains only external code" error

    I should try creating another project with a different design and code and see if the error persists to know if the error is caused by my code or if I clicked something in the Visual Studio that would cause every project I do from here on to get that error.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,746

    Re: "The call stack contains only external code" error

    Quote Originally Posted by JL.19 View Post
    No way to know which line was last executed successfully.
    Yeah, there is. You put a breakpoint at the top of each method and then step through the code line by line. That's why VS includes a debugger.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,742

    Re: "The call stack contains only external code" error

    Even without that, you have shown us the Load event, and a series of events that only happen when you take action, and a tick event. You should be able to rule out at least one of those, and possibly two. If you never got to see the form or press a button, then the control event handlers weren't related. If the timer never got to tick, then that wasn't relevant, and if the form showed up, then the Load event handler isn't relevant.

    You shouldn't have more than one timer on there anyways, but that's not the source of the problem. More than one timer will work, though they will step on each other, which can make timing pretty dubious, so using just one timer is a better solution. There's always a way to do that. The interval just has to be the least common denominator of the intervals you want to use. Then some things happen every tick, others happen every other tick, and so forth.
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    New Member
    Join Date
    Oct 2021
    Posts
    12

    Re: "The call stack contains only external code" error

    Ooh. Really sorry for the inconvenience, I'm new with VS and honestly programming in general so I have yet to know stuff.

    Quote Originally Posted by jmcilhinney View Post
    Yeah, there is. You put a breakpoint at the top of each method and then step through the code line by line. That's why VS includes a debugger.

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,742

    Re: "The call stack contains only external code" error

    If you haven't used breakpoints and code stepping, take the time to learn right away. There is no more powerful tool available to you than that, which may also be why it is so super easy to use. I learned the easy way, which was by having a cat jump off my shoulder and land on the keyboard. That set a breakpoint in the code, which was something I had never seen before. By the time I had gotten rid of the breakpoint, I knew the debugging tools. Of course, if you don't have a cat, you'll have to learn the hard way, but at least you have the internet now, which makes looking things up a whole lot easier.
    My usual boring signature: Nothing

  11. #11
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,674

    Re: "The call stack contains only external code" error

    The call stack contains only external code is not the actual error here. That message is Visual Studio telling you why it can display exactly where the error took place. The dialog in the middle of the screen shot contains the actual error, unfortunately, it's too small to make out what it says.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  12. #12
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,404

    Re: "The call stack contains only external code" error

    From what I can make out it says...
    "Argument exception was unhandled"
    "Parameter is not valid"

    Troubleshooting tips
    "See general tips for this exception"

    Without knowing which line causes the problem by simply stepping through the code and seeing which line causes the exception, I would at least change the string concatenation operations to use the string concatenation operator.

    e.g.
    Code:
    Label1.Text = Label1.Text + "8"
    'should be
    Label1.Text = Label1.Text & "8"
    That assumes you really want to append the character "8" to your text, rather than convert the Text to a number if possible and convert "8" to a number and add them together, and set the text to the summation converted back to a string.
    "Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width