Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

.net 3.5 - IndexOutOfRangeException in VB.NET

Picked up a legacy VB.NET project originally written for version 1.1 of the .NET framework. I'm running Vista with .NET 3.5. I have cleared out all the original error and the project will build; it just wont run.

As far as I can tell, it is trying to run 'LoginForm' but putting breakpoints in doesn't work because the error is thrown before the breakpoints are reached, regardless of where in the file they are placed.

Really can't work out what to do! Any help appreciated.

StackTrace:

System.IndexOutOfRangeException was unhandled
  Message="Index was outside the bounds of the array."
  Source="FirstLine"
  StackTrace:
       at FirstLine.LoginForm.main()
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

EDIT: Terribly sorry, didn't appreciate the code would be of much use because the issue is more that I can't get to it. However, here's the main function:

Shared Sub main()
        Dim p As Process() = Process.GetProcessesByName("FirstLine")
        If p.Length = 1 Then
            'START COPYMINDER
            'Dim expirydate As Date = CDate("01/01/1970")
            'Dim expiry As Integer
            'Try
            '    GetCopyMinderExpiryDate(expiry)
            '    If Not expiry = 0 And Not expiry = 1 Then
            '        expirydate = expirydate.AddSeconds(expiry)
            '        Dim diff As Integer = DateDiff(DateInterval.Day, Date.Now, expirydate)
            '        If diff >= 0 And diff  0 Then
            '    DisplayError((ret_code))
            '    End
            'End If

            'Dim did As String
            'GetCopyMinderDeveloperID(did)
            'If did  "IT" Then
            '    MessageBox.Show("Invalid Developer ID " & did & ". Firstline will now shutdown", "Firstline", MessageBoxButtons.OK, MessageBoxIcon.Error)
            '    End
            'End If

            'END COPYMINDER


            Dim lf As New LoginForm
            If LoginSettings.setting("loginShowErrorOnLine") = "TRUE" Then
                lf.ShowDialog()
            Else
                Try
                    lf.ShowDialog()
                Catch ex As Exception
                    MsgBox(ex.Message)
                    Config.UnlockByUser(Config.currentUser.username)
                    Config.currentUser.UserLoggedOff()
                End Try
            End If
        Else
            Dim prc As Process = p(0)
            SwitchToThisWindow(prc.MainWindowHandle, True)
        End If

    End Sub

Thanks for your responses so far. It's encouraging to see such a helpful community!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Dim prc As Process = p(0) is your problem as it is in the else statements where the the array length can be anything but 1 (0 for instance).

when the length is 0 it will give you the IndexOutOfRange when you try to access the first element.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...