Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,342 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;