Search code examples
vb.netvariablesarraylistvisual-studio-2015.net-4.6.1

Why does Visual Studio throw an exception when declaring a list of string array


I don't know guys but Visual Studio just start acting crazy , my code was working fine I just added one column to a listview added a line of code tested some things and then reloaded the project without saving it (just to revert the project to its last state) but now when I load the project and start debugging I get an exception when declaring a variable on a form i didn't even load it my project structure is like this :

                              |<Settings
Splash screen --> Main Form --><Equalizer
                              |<Tags

The above meant that my project starts with splash screen and after 3 seconds it loads the main form which acts like a home for the app and then from there you can do regular media player stuff and also call three other forms {settings, equalizer and tags}, so when I start the project the splash screen load normally, the second it tries to call main form it throws an exception on this piece of code

Dim extendedinfoarray As New List(Of String())

Here is the exception info :

System.ArgumentOutOfRangeException occurred
HResult=-2146233086
Message=DisplayIndex value is out of bounds. Value must be greater than or equal to 0 and less than or equal to number of columns minus 1.
Parameter name: DisplayIndex
ParamName=DisplayIndex
Source=System.Windows.Forms

StackTrace:

at System.Windows.Forms.ColumnHeader.set_DisplayIndex(Int32 value)
at MrAudio.TaggingForm.InitializeComponent() in D:\Visual Studio Project Files\MediaPlayerFullFormProj\MediaPlayerFullFormProj\TaggingForm.Designer.vb:line 1668
at MrAudio.TaggingForm..ctor() in D:\Visual Studio Project Files\MediaPlayerFullFormProj\MediaPlayerFullFormProj\TaggingForm.vb:line 8

I'm using .NET 4.6.1

So what can be causing Visual Studio to start throw a random exception like this, I thought it can't throw an exception when declaring a variable. Can it?

Thanks in advance,

PS: this is my first question on StackOverflow if I didn't provide enough details just ask.


Solution

  • The problem is related to the ListView itself after removing a column, adding another one and arranging it will cause this problem

    Quick fix :

    Edit form designer file search for the ListView settings section change the column arrange to the correct one , or remove all columns, compile and start, then add those columns again and that should fix the problem.