✅ 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
Please post your code on $code instead
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/BlazeBin - uipqjqrtgsij
A tool for sharing your source code with the world!
Ok,try setting a breakpoint in FillDataGrid and stepping through
now the exception was thrown here
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
why now? lol
i didn't modify a single thing
except the connection string when connecting to the database
Well there isn't much else than could be null in that scenario
any suggested solution?
Try splitting that instruction into two parts to verify
So we know for sure that's the problem
can you elaborate?
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 returnedi got this in the previous window
which is the login
Did you try to step over?
The problem is in that class, so I'm not sure why you have a breakpoint outside it
still the same error
I think that's just the exception sign
But I asked you to put a breakpoint in FillDataGrid
Did you do that?
yes
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
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
That's why I'm telling you to step through with the debugger
Nah, you're not Listening
i keep stepping through and it keeps showing me those 3
:' )
i press F10 and it cycles through them
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
the constructor
So set a breakpoint in the ctor
You're clearly jumping over the entire thing, and something in it is throwing
man, sorry i'm exhausted and I have to go back home from work.
Im at a computer now, if you have 5 more min I'm sure we can fix it if you screenshare
yeah sure!
that would be a huge help
#dev-vc-1
just a sec
would you be able to undeafen?
so I can speak
or should we do text
I neither have a headphone nor a microphone right now : c
ok
just screenshare then
for some reason its not allowing me to
would you be able to call in an hour?
¯\_(ツ)_/¯
maybe, maybe not
sorry I dont know why its not letting me
and we're kind of closing the building
so i have to leave
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 🙂
alright, thank you, and i apologise
@mammothcrytie@pobiega He's pressing F10 which is stepping over, instead of F11 which would step into the place where the exception is
well yes, but if there was a BP inside the ctor, it would break there too
which is what I was saying
Yeah, that'd be easier if he cant figure out how to step through the code properly
@pobiega hey there!
heya
are you available ?
sure
for a few minutes
alright sure
i can hear you but I can't seem to find a microphone
its fine
Okay
thank you so much and im sorry for bothering you, good night!
$close 🙂
Use the /close command to mark a forum thread as answered