Results 1 to 5 of 5

Thread: [RESOLVED] VB Project Runs But Only In Debug

  1. #1

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Resolved [RESOLVED] VB Project Runs But Only In Debug

    I've got a simple VB.NET project which has been running great for over a year now. The boss came to me and asked for some changes to it. The main one being that the project now looks for a text file to get a bunch of configuration defaults before running. Okay cool, so I run the project from VS in debug and it works perfect. Now the boss wants to see it in action so I copy the stand-alone exe file over to the server and he runs it but we get an error message. See the attached snippet shot.

    So I look into the details and it tells me that the error occurred at line #239 of my project which is the line shown in red in this code:
    Code:
    Private Sub GetDefaults()
            Dim vFile As String = "\\a_long_novell_path\CONFIG.txt"
            If File.Exists(vFile) Then
                Dim vDefaults() As String = File.ReadAllLines(vFile)
                Dim s As String
                For Each s In vDefaults
                    If s.Substring(0, 1) <> "#" Then
                        If s.Contains("EngSvrPath") Then
                            vdbname = s.Substring(s.IndexOf("=") + 2) & "Engineering\Databases\DwgChkList.mdb"
                        End If
                        If s.Contains("CheckListTop") Then
                            lblTopText.Text = s.Substring(s.IndexOf("=") + 2)
                        End If
                        If s.Contains("CheckListBot") Then
                            lblBottomText.Text = s.Substring(s.IndexOf("=") + 2)
                        End If
                    End If
                Next
            Else
                MsgBox("Oops! The configuration file is missing" & vbCrLf & "Please contact administrator for assistance", MsgBoxStyle.OkOnly)
                Windows.Forms.Application.Exit()
            End If
        End Sub
    I went back and tested this at my computer and sure enough it produces the same error. BUT ... I can run the project inside of VS and it works just fine. I don't know where to turn on this one because I have never seen a project work in VS and then not work when I run just the exe. Just in case this is needed, here is the Exception Text section of the details:

    ************** Exception Text **************
    System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
    Parameter name: length
    at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
    at WindowsApplication1.Form1.GetDefaults() in C:\Engineering\Eng Utilities\DwgCheckList(01)\DwgCheckList(01)\Form1.vb:line 239
    at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e) in C:\Engineering\Eng Utilities\DwgCheckList(01)\DwgCheckList(01)\Form1.vb:line 69
    at System.EventHandler.Invoke(Object sender, EventArgs e)
    at System.Windows.Forms.Form.OnLoad(EventArgs e)
    at System.Windows.Forms.Form.OnCreateControl()
    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
    at System.Windows.Forms.Control.CreateControl()
    at System.Windows.Forms.Control.WmShowWindow(Message& m)
    at System.Windows.Forms.Control.WndProc(Message& m)
    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
    at System.Windows.Forms.ContainerControl.WndProc(Message& m)
    at System.Windows.Forms.Form.WmShowWindow(Message& m)
    at System.Windows.Forms.Form.WndProc(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    Attached Images Attached Images  
    Last edited by Vladamir; Jan 12th, 2015 at 04:18 PM.

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: VB Project Runs But Only In Debug

    It's likely the problem is that s is an empty string.
    IF it's empty, the substring as it is will error out.

    you can do is add in another check to see if there is a length first...
    Code:
    If s.length>0 andalso s.Substring(0, 1) <> "#" Then
    The andalso will cause it to short circuit so if the length is 0, it fails and will skip the SubString test.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Re: VB Project Runs But Only In Debug

    That was my first thought too. But the text in the file has not been changed and like I said this works perfect in debugger

  4. #4
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: VB Project Runs But Only In Debug

    Quote Originally Posted by Vladamir View Post
    But the text in the file has not been changed and like I said this works perfect in debugger
    From the error message, it appears that GetDefaults is being called from the Form.Load event handler.

    As you may or may not know, when developing on a 64 bit system, any errors generated in the Form.Load event handler while running from the IDE are swallowed, and the code in the handler following the error is ignored i.e. not executed. The Form still loads and appears to function as "normal", though.

    So my guess is you are developing on a 64 bit system. You are calling GetDefaults fairly late on in the Load event handler, and you have a blank line in the text file, probably near or at the end of it. The late call and the error happening near to the end of reading the text file would mean you are unlikely to spot anything is wrong while you are developing the app.

    Running the standalone .exe (outside the IDE) will raise exceptions as normally expected, though.

    Just my best guess based on what you have said so far.

  5. #5

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Re: VB Project Runs But Only In Debug

    Inferrd, thanks for the info. I wasn't aware of that at all and yes, I'm developing on a 64bit system. So I looked at the text file and sure enough I had a blank line at the end of it. I took that out and the standalone runs fine now. Many thanks.

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