John
John

Reputation: 3945

Null Reference Exception.....but the value is NOT NULL

I have a line of code string managerFirstName = "[email protected]"; that is flagging as NULL. How is this NULL....its a string that is populated when its created....is there an error with my VS2013? or a setting I need to change? enter image description here enter image description here

Upvotes: 2

Views: 3557

Answers (7)

Jack
Jack

Reputation: 59

I have had this issue with VS 2022. Where this happens I get null reference and errors. I have found that this was because my debug configuration was set to Release and not debug.

enter image description here

Upvotes: 1

Zubaer Naseem
Zubaer Naseem

Reputation: 574

I faced this problem when I was manually skipping execution of few lines (apparently unrelated code section).

Upvotes: 0

John
John

Reputation: 3945

Would just like to say thank you to everyone who helped me out with this Q....I found the cause...just above the

ADUser managerUser = GetManagerNameForOrgUnit(coreData.OrgAssignment_0001.OrgUnit.ID, coreData.PersonnelNo);

there is an if statement, which during testing always stops the code from hitting GetManagerNameForOrgUnit(), I have been manually stepping over this if.

I commented it out and the code works fine.

Thanks again

Upvotes: 0

SSS
SSS

Reputation: 5403

It's not the highlighted line that is crashing - the IDE is highlighting the wrong line.

The stack trace you posted mentions RFS.DotNetNuke.Service.ActiveDirectorySynchronise.something. Try and look for a line of code that uses that object - probably the line of code above the highlighted line (GetManagerForOrgUnit). Examine each of the parameters for that call and see if you can find a null reference.

Upvotes: 4

Sentinel
Sentinel

Reputation: 3697

If the problem is code related, not build, this looks like a threading issue. Try wrapping the whole function in a lock, and looking for how contexts could be getting mangled.

Upvotes: 1

Sentinel
Sentinel

Reputation: 3697

This used to happen to me in VS2k13 a lot. Basically your code is not getting rebuilt. Even after a clean/rebuild, some code refuses to compile. What used to work for me was1. Clean/rebuild. 2. Make a code change in the area of code you are looking at. 3. Put a breakpoint in the calling method. 4. Debug and f11 step line by line to your code change.

Upvotes: 0

Sampath
Sampath

Reputation: 1211

Try after removing Visual Studio component cache.

  1. Close Visual Studio (ensure devenv.exe is not present in the Task Manager) Delete the directory:

    %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
    
  2. Restart Visual Studio

Upvotes: 0

Related Questions