0

I moved a C# solution from one computer (running VS2015) to another (running VS2017). The solution contains some class libraries and an ASP.net website project.

When I run my application on the new computer, I get runtime exceptions at seemingly random places throughout my code. These exceptions say that I have a NullReferenceException for objects retrieved from the database. But if I highlight the error code in the editor to evaluate the problematic expression, it's showing that the object in question actually isn't null at all.

enter image description here

In the above screenshot, you'll see the compiler is reporting that the "get" request for my Player object was null. But if I hover over the FullName property for this Player object, it is populated (as seen in the picture, his full name is "Thomas Rawls". This means the Player object could not have been NULL, no?

Here are my specific exception details.

enter image description here

I copied my code to the new machine twice, and restored it's database twice, but I continue to get these NULL exception errors. The web site still runs fine on my old machine.

Any clue as to what could be happening here?

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
bperniciaro
  • 901
  • 2
  • 12
  • 30
  • Visual Studio or the computer have nothing to do with this. You tried to access a null value. `Player` is almost certainly null. – Panagiotis Kanavos May 30 '17 at 12:28
  • Please *don't* post screenshots of your code or exception. Screenshots can't be compiled or googled. If you want further help post the code that should be loading `Player`. Are you using EF perhaps, and forgot to include a related class? – Panagiotis Kanavos May 30 '17 at 12:29
  • But the problem is Player is not null. If you look closely at the screenshot, I'm hovering over the Player's FullName property and it is loading. If I run the app a second time the reference error will be gone- so it's almost like a timing issue. All of my references are to projects within the solution that build. – bperniciaro May 31 '17 at 13:14
  • The only difference between my two setups is one is using VS2015/SQL2012 Express and the other VS2017/SQL2016 Express. – bperniciaro May 31 '17 at 13:16
  • Debug your code. Talking about screenshots without reproducible code is meaningless. As for the combination - I also use VS 2015, 2017, 2017 Update 3 preview, SQL Server 2014, 2016 and 2017 on a container, on the same machine. – Panagiotis Kanavos May 31 '17 at 13:18
  • This is clearly not a duplicate question if you read what I wrote. My issue is that the compiler is reporting a null reference error when in fact the debugger shows the variable in question is not NULL. Also, these are occurring randomly so I can't simply set a breakpoint and determine why a particular variable is NULL. – bperniciaro Jun 01 '17 at 04:47

0 Answers0