Null Reference error but it's not null?
System.NullReferenceException: 'Object reference not set to an instance of an object.'
Typically yeah this is an easy error to solve, but I already have defined this?
Variable
j
is already defined as an int with a value of 0: int j = 0;
, so why is this error being thrown?35 Replies
Ints cannot be null so it's likely something different which is the issue
Are you debugging in release mode by any chance?
No, still in debug
is
Optimize code
set to true in ur project settings?is it set to true by default? If not, then no
check ur project settings in case
No it is not checked
show us the call stack pls
ur probably running multiple threads
Correct
So all this code is in the function
RefreshJournals
i assume the exception was thrown in a different thread but VS incorrectly shows it was thrown in this thread instead
I'm going to launch the exe from cmd so I can see the crash output
Okay for some reason it launches then immediately exits, but the form stays up for a few seconds after
Let me enable console for forms
can you send the call stack from the exception?
Yes hold on
First here is the console output
Where is the call stack again?
in visual studio
yes I know
But like Ctrl Alt C doesn't work
you should see a window like this on the bottom right of your VS
ur program needs to be running and breakpointed somewhere first
you should see it when your VS shows the exception
i assume j++ is at line 178?
correct
Ironic im better at threading in assembly and C without libraries than C# with libraries 😭
is JournalsDrive not null?
are you changing the value of j somewhere else other than from this line?
im such an idiot
JournalsDrive was null
because i commented out the wrong one 😭
Thank yall so much
But it might not be over because I don't think it successfully read the ntfs journals
you were probably running an older version of ur program thus why VS pointed at the wrong line
I mean I did clean and recompile
I solved an error and gained 3 more
im going to bed
thanks yall <3
Maybe I'm wrong but I noticed you create are overwriting the created thread everytime in
foreach(tab ......)
Tread thread = new ...... ==> every tab the reference is distroyed by the new thread.
You probably need a list or an array of threads
it works just fine but thanks anyways :3