I’ve read that Convert.ToString should handle null, but it doesn’t work when it’s passed a null object in my code
In this case the object “Name” is null.
var name = Convert.ToString(Name.LastName);
I get Object reference not set to an instance of an object.
The exception is not caused by
Convert.ToString().The exception is in your code because you are trying to get the value of
LastNamefrom a null reference. This causes the runtime exception.To fix it, you’ll need to check that
Nameis not null before you try to accessLastName.