C
C#15mo ago
SupsXito

✅ C# null exception with SQL

I was trying to deploy my application to another computer to try it, and I got an error where it couldn't located the attached mdf file so i fixed the connection string in visual studio and I started getting "Object reference not set to an instance of an object" in the application and the error : System.NullReferenceException HResult=0x80004003 Message=Object reference not set to an instance of an object. Source=DoumaClientDatabase StackTrace: at Douma_Client_Database.MainWindow.FillDataGrid()MainWindow.xaml.cs:line 82 my code should be here : https://paste.mod.gg/uipqjqrtgsij/0
BlazeBin - uipqjqrtgsij
A tool for sharing your source code with the world!
52 Replies
Pobiega
Pobiega15mo ago
Please post your code on $code instead
MODiX
MODiX15mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
SupsXito
SupsXitoOP15mo ago
I posted it on https://paste.mod.gg/uipqjqrtgsij/0 because its a little too long
BlazeBin - uipqjqrtgsij
A tool for sharing your source code with the world!
Pobiega
Pobiega15mo ago
Ok,try setting a breakpoint in FillDataGrid and stepping through
SupsXito
SupsXitoOP15mo ago
now the exception was thrown here
string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
string CmdString = string.Empty;
string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
string CmdString = string.Empty;
Pobiega
Pobiega15mo ago
Ok, likely it's that the indexing failed Ie, your configuration didn't find any connStr with that name ConfigurationMmanager always makes me think of .net framework
SupsXito
SupsXitoOP15mo ago
why now? lol i didn't modify a single thing except the connection string when connecting to the database
Pobiega
Pobiega15mo ago
Well there isn't much else than could be null in that scenario
SupsXito
SupsXitoOP15mo ago
any suggested solution?
Pobiega
Pobiega15mo ago
Try splitting that instruction into two parts to verify So we know for sure that's the problem
SupsXito
SupsXitoOP15mo ago
can you elaborate?
Pobiega
Pobiega15mo ago
On phone so hard to write code, do var constr = configmanager.connstr[...]; Then access the .connectionString property in a second instruction That lets you step through and see what the configmanager returned
SupsXito
SupsXitoOP15mo ago
No description
SupsXito
SupsXitoOP15mo ago
i got this in the previous window which is the login
Pobiega
Pobiega15mo ago
Did you try to step over? The problem is in that class, so I'm not sure why you have a breakpoint outside it
SupsXito
SupsXitoOP15mo ago
still the same error I think that's just the exception sign
Pobiega
Pobiega15mo ago
But I asked you to put a breakpoint in FillDataGrid Did you do that?
SupsXito
SupsXitoOP15mo ago
yes
Pobiega
Pobiega15mo ago
That means it's something else throwing your null exceptio Set a breakpoint in the constructor Step through the entire thing until you find it
SupsXito
SupsXitoOP15mo ago
it keeps referencing the constructor and the filldatagrid in the call stack thats it i've been at it for almost 5 hours now and couldn't find a specific cause
Pobiega
Pobiega15mo ago
That's why I'm telling you to step through with the debugger
SupsXito
SupsXitoOP15mo ago
No description
Pobiega
Pobiega15mo ago
Nah, you're not Listening
SupsXito
SupsXitoOP15mo ago
i keep stepping through and it keeps showing me those 3 :' ) i press F10 and it cycles through them
Pobiega
Pobiega15mo ago
Thats when the exception has already been thrown You need to find where it is null before you access it Ie, at what line where you when you pressed F10 and it threw Thats the line we care about
SupsXito
SupsXitoOP15mo ago
the constructor
Pobiega
Pobiega15mo ago
So set a breakpoint in the ctor You're clearly jumping over the entire thing, and something in it is throwing
SupsXito
SupsXitoOP15mo ago
man, sorry i'm exhausted and I have to go back home from work.
Pobiega
Pobiega15mo ago
Im at a computer now, if you have 5 more min I'm sure we can fix it if you screenshare
SupsXito
SupsXitoOP15mo ago
yeah sure! that would be a huge help
Pobiega
Pobiega15mo ago
#dev-vc-1
SupsXito
SupsXitoOP15mo ago
just a sec
Pobiega
Pobiega15mo ago
would you be able to undeafen? so I can speak or should we do text
SupsXito
SupsXitoOP15mo ago
I neither have a headphone nor a microphone right now : c
Pobiega
Pobiega15mo ago
ok just screenshare then
SupsXito
SupsXitoOP15mo ago
for some reason its not allowing me to would you be able to call in an hour?
Pobiega
Pobiega15mo ago
¯\_(ツ)_/¯ maybe, maybe not
SupsXito
SupsXitoOP15mo ago
sorry I dont know why its not letting me and we're kind of closing the building so i have to leave
Pobiega
Pobiega15mo ago
not a problem I'm just not comitting to being here in an hour :p Ping me and if I am, I'll help if not.. well, then I'm not 🙂
SupsXito
SupsXitoOP15mo ago
alright, thank you, and i apologise
joren
joren15mo ago
@mammothcrytie@pobiega He's pressing F10 which is stepping over, instead of F11 which would step into the place where the exception is
Pobiega
Pobiega15mo ago
well yes, but if there was a BP inside the ctor, it would break there too which is what I was saying
joren
joren15mo ago
Yeah, that'd be easier if he cant figure out how to step through the code properly
SupsXito
SupsXitoOP15mo ago
@pobiega hey there!
Pobiega
Pobiega15mo ago
heya
SupsXito
SupsXitoOP15mo ago
are you available ?
Pobiega
Pobiega15mo ago
sure for a few minutes
SupsXito
SupsXitoOP15mo ago
alright sure i can hear you but I can't seem to find a microphone
Pobiega
Pobiega15mo ago
its fine
SupsXito
SupsXitoOP15mo ago
Okay thank you so much and im sorry for bothering you, good night!
Pobiega
Pobiega15mo ago
$close 🙂
MODiX
MODiX15mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server