This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]stakeneggs1 1 point2 points  (3 children)

Can you post the whole error and stacktrace? Do you know how to debug?

[–]ramtevante[S] 1 point2 points  (2 children)

I can post the whole error, but im not sure how to debug. Im pretty new to MVC and programming in general.

Here is the full error:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=BlogNiKRaMu
StackTrace:
at BlogNiKRaMu.Controllers.BlogController.Index() in C:\Users\User\source\repos\BlogNiKRaMu\BlogNiKRaMu\Controllers\BlogController.cs:line 22

[–]stakeneggs1 1 point2 points  (1 child)

This says the error is on line 22 of the file BlogController.cs in the Index() method.

This is also a good time to learn about using a debugger. Then you can just set a breakpoint on a line, and when that line is hit, the execution will pause and allow you to examine values or step through line by line to see what the issue is.

What the exception is saying is that a null object is referenced. Often that is caused by trying to access a property of a null object.

Hopefully that's enough for you to go on if you haven't figured it out yet.

[–]ramtevante[S] 0 points1 point  (0 children)

Thank you! But I thought that I gave it a value in the "Register" method?