C# array problem // Error loading configuration : Index was outside the bounds of the array
Hii! I'm new to this group i tried to fix it yesterday all day and decided to ask for help.
I moved some settings files to a webserver and after updating code, i trigger the error in title. The problem is that it works perfect with index==0, but if i use any other index, it will give the error in title.
As an exemple, if i select the second element in list(index==1) it will trigger that error, even if Server1.txt and Server2.txt have the same content.
All the txt files have elements separated by space
I'm open to any advice, thanks❤️
27 Replies
Jesus
Well, uh,
In any case, if you get an index out of bounds when trying to access
array[1]
that means... that index does not exist
Why—
why are you using this.server2
kinds of fields just to move values from an array to a list...?
Why webclient?
Why casting to object
...?i want to read all elements inside the txt files from a webserver, so i can change anything names without recompiling source..
Sure, okay, you can do that
You're just doing some really weird things along the way lol
i'm aware that the code looks really messy 😄 but i can't understand where i check a wrong index, i only use index+1 once when reading server txt file, cuz they start from server1, and index is 0 based..
Well, run the debugger
if i select index0, it will load server1 perfectly, but if i select index 1, it fails to read server2.txt wich has exactly the same content
i tried it, it reads all the values fine, but still triggers that index outside array
Which line exactly?
Post your code on $paste or somewhere and tell me the line number
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
https://paste.mod.gg/oyofkxceyggu/0 on line 94 & 103, 94 says there is not enough configuration, but i debugged the arrays & data received and worked even on index 1(server2.txt)
BlazeBin - oyofkxceyggu
A tool for sharing your source code with the world!
ex.Message
says index is out of range, yeah?
But if so, then that means your check in line 101 ain't checkingyep, i had to remove that to get the index outside array
How does your config file look?
Because
.Split()
with no delimiters splits by whitespaceAngius
REPL Result: Success
Result: string[]
Compile: 389.884ms | Execution: 30.872ms | React with ❌ to remove this embed.
So if you're storing each config in its own line, and it's all delimited by spaces...
it's not doing what you think it's doing
Why not use JSON in the first place?
i'll try that, i started by reading the files from a txt file in main directory, so my next step was to move that code to webserver, and continue improving it
JSON really would be so much more sane
Or, if you want to keep your current code, pay attention to what you're splitting your strings on
Instead of yoloing it with
.Split()
that will split on every whitespacei'll try it, thanks❤️
yep, all files have the elements separated by space.... this is an exemple of server[x].txt : "0x01CC7A6C 0x01BDB658 0xC 0x18 0x200 0x204 0x208 0x0 0x4B0 0x4B4 0x4B8 0x640 0x180 0x20 0x50 0x019EA0C4 0x0 0x0 0x0 0x0 0x0 0x7A0 0x5C 0x01CC79EC 0x60 0x7E4 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0"
So a
or
?
it may look like a mess, but i'm better at php than c#, and i did a panel to manage all that mess.
like this
Bob 42 cars cooking Agnes 14 fitness rugby
in all 3 files, the elements are separated by space, and all of them are on a single line
yeah, no wonder your code doesn't work
:d it was working when i did the first version that was reading values from exe directory, but i wanted to move them to a webserver, and it become a big mess
The format of your config would lend itself to being a big mess, yes
i also use json for some parts of my code, but i would really need to make it as txt, at least this part, so i will save half the size of the file, there will be many post requests involving those files....
At least use CSV then
That way you can split the individual configs on
\n
and individual items in each config on ,
but it won't be the same result? atm i use \n for endline and " " for elements
So you are not storing them all in a single line after all?
so, to clarify it, there are 3 files, each with only one big line with elements separated by " "
a file for binaries, one for names, and one for memory adresses