C# Entity Framework with ASP.NET MVC Data Access Design Patterns Reviewing the Comic Book Artists Repository

Object reference not set

I got the following error

"Object reference not set to an instance of an object."

Line 19: </div> Line 20: <div class="col-xs-8 col-sm-8"> Line 21: @Model.Series.Title Line 22: </div> Line 23: </div>

It shows that the problem is in the line

@Model.Series.Title

Does anyone have any suggestions on what to try debugging?

1 Answer

Fredrik Rönnehag
Fredrik Rönnehag
2,341 Points

Hard to know if I can't see the code or the entire project. Can you paste the code?

Object reference not set to an instance of an object. Means exactly what it says, you are trying to use a null object as a referenced object. You are trying to access an object without instantiating it. You might need to use the "new" keyword to instantiate it first, to create an instance of the object.

Example:

public class MyCar
{
   public int Year {get; set;}
}

MyCar Car;
Car.Year = 0; // This will cause the error Object reference not set to an instance of an object.

//Proper way//

MyCar car = new MyCar();
car.Year = 0;