C
C#12mo ago
! Natan

✅ Crazy C# Beahviour

This is a very basic problem that it's getting me mad. Since it doesn't work in this case but on an online c# compiler is works more than fine. So I have this string that I want to split to retrive different datas and this is what I get. Here's the string and the snippet.
string _raw = "1689514251*[37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1]()"

_raw = _raw.Remove(_raw.Length - 3).Split('[')[1] #I Remove before the last 3 chars, I don't need them, and then I split it in two half, i want only the content inside []
string _raw = "1689514251*[37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1]()"

_raw = _raw.Remove(_raw.Length - 3).Split('[')[1] #I Remove before the last 3 chars, I don't need them, and then I split it in two half, i want only the content inside []
Error That I get: System.IndexOutOfRangeException: 'Index was outside the bounds of the array.' Any kind of help would be more than apriciated
84 Replies
HimmDawg
HimmDawg12mo ago
Are you absolutely 100% certain that you don't do other stuff in between? Doing what you have posted should work. It does for me tho
!            Natan
! Natan12mo ago
I know, you want a sceen? Since this is exactly what I'm doing the problem is that in the watcher the _raw string is singed as the 1689514251* part and the other is just gone
HimmDawg
HimmDawg12mo ago
sure, post the code here
MODiX
MODiX12mo ago
Jimmacle
REPL Result: Success
string _raw =
"1689514251*[37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1]()";

Console.WriteLine(_raw.Remove(_raw.Length - 3).Split('[')[1]);
string _raw =
"1689514251*[37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1]()";

Console.WriteLine(_raw.Remove(_raw.Length - 3).Split('[')[1]);
Console Output
37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1
37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1
Compile: 642.028ms | Execution: 77.481ms | React with ❌ to remove this embed.
Jimmacle
Jimmacle12mo ago
¯\_(ツ)_/¯
MODiX
MODiX12mo ago
Jimmacle
REPL Result: Success
string _raw =
"1689514251*[37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1]()";

var start = _raw.IndexOf('[') + 1;
var end = _raw.IndexOf(']');
Console.WriteLine(_raw[start..end]);
string _raw =
"1689514251*[37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1]()";

var start = _raw.IndexOf('[') + 1;
var end = _raw.IndexOf(']');
Console.WriteLine(_raw[start..end]);
Console Output
37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1
37197921;ON;1689514258;12750;tropossu;3,12750;tropossu;1689514250;3|12749;folundo8;1689514245;1|12748;tropossu;1689514238;3|12747;folundo8;1689514233;1|12746;tropossu;1689514227;3|12745;folundo8;1689514222;1|12744;tropossu;1689514215;3|12743;folundo8;1689514210;1|12742;tropossu;1689514203;3|12741;folundo8;1689514198;1
Compile: 555.737ms | Execution: 89.269ms | React with ❌ to remove this embed.
Jimmacle
Jimmacle12mo ago
more readable imo
!            Natan
! Natan12mo ago
same reaction honestly
!            Natan
! Natan12mo ago
!            Natan
! Natan12mo ago
I am 100% sure of the reutrn var of the Method Called (RawLeaderboardBody) I've been debugging it for a lot and I've come to the conlusion that the problem is loacated at the 2nd line inside the try statement
Jimmacle
Jimmacle12mo ago
the only possibility there is that RawLeaderboardBody(_AID) isn't returning what you think it is
!            Natan
! Natan12mo ago
but it is, I am 100% sure I removed all the logs but the value is correct
Jimmacle
Jimmacle12mo ago
if you set a breakpoint on the second line of your try block, what does it tell you the value of _raw is? or just print it to the console or something
!            Natan
! Natan12mo ago
i send you a screen the crazy thing is that on console has a value in the editor tracer it has anotherone no my bad if I add a breakpoin the values are the same
!            Natan
! Natan12mo ago
Jimmacle
Jimmacle12mo ago
for the sake of experiement, what if you try the version i showed?
var start = _raw.IndexOf('[') + 1;
var end = _raw.IndexOf(']');
_raw = _raw[start..end];
var start = _raw.IndexOf('[') + 1;
var end = _raw.IndexOf(']');
_raw = _raw[start..end];
!            Natan
! Natan12mo ago
Parameter lenght cannot be lower than 0 basically he's telling us that there is no ] char
Jimmacle
Jimmacle12mo ago
so end is -1 in the debugger?
!            Natan
! Natan12mo ago
end is not -1 it's 348
Jimmacle
Jimmacle12mo ago
then it is in the string
!            Natan
! Natan12mo ago
yeah but then he goes crazy
Jimmacle
Jimmacle12mo ago
"goes crazy" isn't a helpful issue description 😛 what's the value of start?
!            Natan
! Natan12mo ago
yeah sorry man, I realized I'm not beein that helpful sadge
Jimmacle
Jimmacle12mo ago
and can you give me the entire exception when it fails?
!            Natan
! Natan12mo ago
and _raw's value it's still the same yeah
Jimmacle
Jimmacle12mo ago
because everything is pointing to nothing being wrong with this part of your code
!            Natan
! Natan12mo ago
ok ok little update, removing the breakpoint gives us new values
Jimmacle
Jimmacle12mo ago
yeah i just saw your issue looking at the code again you're splitting on , on the next line where is a , anywhere in your string?
!            Natan
! Natan12mo ago
jesus no wait there is
Jimmacle
Jimmacle12mo ago
it looks like it uses ; as a separator, not ,
!            Natan
! Natan12mo ago
no after the 3 in the first row
Jimmacle
Jimmacle12mo ago
ah yeah i see
!            Natan
! Natan12mo ago
or better second
Jimmacle
Jimmacle12mo ago
well, i'm guessing the actual issue is somewhere else in your parsing code either way
!            Natan
! Natan12mo ago
Jimmacle
Jimmacle12mo ago
that makes 0 sense given the debugger values you told me click "show call stack"
!            Natan
! Natan12mo ago
nah the debugger was stuck before the error
!            Natan
! Natan12mo ago
Jimmacle
Jimmacle12mo ago
okay, that solves it your string doesn't contain a [ or a ]
!            Natan
! Natan12mo ago
Jimmacle
Jimmacle12mo ago
exactly so RawLeaderboardBody isn't returning what you think it is
!            Natan
! Natan12mo ago
yeah by getting a closer look it has a value then it has another one without any change in the code
Jimmacle
Jimmacle12mo ago
i mean, that doesn't happen
!            Natan
! Natan12mo ago
I know
Jimmacle
Jimmacle12mo ago
values don't randomly change in code, something is happening that changes it or it was never right to begin with 😛
!            Natan
! Natan12mo ago
I have just to look on it nah the return is correct, it just truncates while passing from the function a to the function b at the '*' the funny thing it's that in the debugger is wrong in the console is right
Jimmacle
Jimmacle12mo ago
again, values don't randomly change
!            Natan
! Natan12mo ago
they do when you ingenuly set them to be an edited version of themself updates tomorrow, I spent to much time on this today
Jimmacle
Jimmacle12mo ago
that's... not random
!            Natan
! Natan12mo ago
this is leading me crazy
!            Natan
! Natan12mo ago
Jimmacle
Jimmacle12mo ago
seems pretty obvious to me the API you're hitting doesn't return the same result every time which is the first thing i said
MODiX
MODiX12mo ago
Jimmacle
the only possibility there is that RawLeaderboardBody(_AID) isn't returning what you think it is
Quoted by
<@901546879530172498> from #Crazy C# Beahviour (click here)
React with ❌ to remove this embed.
Jimmacle
Jimmacle12mo ago
this is why it's important to debug using a minimal reproduction of the issue, you have things in your code that none of us can even test it's not magically changing, you're calling the whole method multiple times and the API is returning something different for different calls of your method
Anchy
Anchy12mo ago
if this is for the it.bidoo.com auctioning website then I don't think they offer an API (from what I can tell) and the issue probably lies in your parser
Jimmacle
Jimmacle12mo ago
so this is potentially sketchy scraping to begin with?
Anchy
Anchy12mo ago
possibly the website is in another language so I am not entirely sure
Jimmacle
Jimmacle12mo ago
considering the whole site is gated with a captcha i'm gonna go with yes @impingu_ unless you have permission to scrape this site we can't help you any further and again, next time don't lead us on a wild goose chase with misleading repro cases
!            Natan
! Natan12mo ago
it does, + it's completly ok to scrape that API, it just retriving public infos also just a little precisation, as you can see from the video it’s a c# related problem in a very specific situation with has nothing to do with the apis
SinFluxx
SinFluxx12mo ago
The video just shows that you got a different value returned the two times you called the API
!            Natan
! Natan12mo ago
I didn't call the api 2 times
SinFluxx
SinFluxx12mo ago
In your video it starts at line Line 58, goes to Line 63, then back to Line 58, then to Line 63, so it would have made a call to the API both times it hit Line 58?
!            Natan
! Natan12mo ago
yeah but have a look at the watcher, the _raw string gets the right value also I just looped this function always the right return
SinFluxx
SinFluxx12mo ago
It shows it has the right value the first time, it doesn't show it has the right value the second time
!            Natan
! Natan12mo ago
!            Natan
! Natan12mo ago
right value
!            Natan
! Natan12mo ago
!            Natan
! Natan12mo ago
still right
!            Natan
! Natan12mo ago
!            Natan
! Natan12mo ago
now wrong
SinFluxx
SinFluxx12mo ago
so right the first time you call it, wrong the second time you call it... i.e. seems like a different value coming from your API call
!            Natan
! Natan12mo ago
Where do I call it the second time?
SinFluxx
SinFluxx12mo ago
well two of those screens have a breakpoint at line 64 but with different watched values so I assume you must have, hard to tell exactly when you're cropping the screens
Jimmacle
Jimmacle12mo ago
why are you insisting that C# is magically changing your string and not even considering the very likely possibility that the API is returning different results? this is easy to test, call the API in something like postman multiple times and see what happens rule #1 of debugging is isolate the problem
Vi Ness
Vi Ness12mo ago
Code runs from top to bottom. You're showing us that it has the correct value on Line 64 but then later has the incorrect value on Line 61. The only way to get back up to Line 61 is to come from the top of your Update method, which includes Line 58. You're getting a new _raw string from RawLeaderboardBody, it's not changing your old one. That's why people have been telling you that your API doesn't return the same result every time
!            Natan
! Natan12mo ago
Just checked and the API does always return the same value, checked in axios for node, in another c# project and trought fiddler
Anchy
Anchy12mo ago
show code for RawLeaderboardBody method
MODiX
MODiX12mo ago
! Natan
Quoted by
<@186327148519227394> from #Crazy C# Beahviour (click here)
From !            Natan
React with ❌ to remove this embed.
Anchy
Anchy12mo ago
check the status code of your http get response, it is possible you are being rate limited or something else so your result will end up being null if so
Vi Ness
Vi Ness12mo ago
Can you show us where you're calling Update and how/if _AID is being changed?
!            Natan
! Natan12mo ago
Just to let you know the issue has been fixed I just changed the Call for Update from the constructor, below the assignation of _AID, to the static void main of the program class 🤯
HimmDawg
HimmDawg12mo ago
I am amazed that is even ran without async await when
!            Natan
! Natan12mo ago
No need to await it, since it wouldn't bring me any benefit in general inside my project, I need everything to run sincronously
Accord
Accord12mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts