I'm experiencing something pretty when testing a simple Umbraco page.
I get a null reference exception, but according to the stacktrace, the line triggering the exception has nothing but a curly bracket.
Here's the codeblock in question:
@if (Model.BlogCollection != null) // confirmed that this is not null, if it's null it just skips the block correctly.
{ // line causing the exception according to stacktrace
<div class="blogs-content">
<div class="first-blog">
</div>
@foreach (var blog in blogs)
{
<div class="blog">
</div>
}
</div>
}
Has anyone experienced something like this, and figured out what is causing it ?
So this is the "downfall" of razor. There is infact code behind in a razor view, in that at runtime (unless configured otherwise) the view is compiled. As a result errors, particularly null references, can be reported on incorrect lines.
The odds are, look for the next razor code in your file after the line being reported (e.g. something like @object.dosomething.this and you'll find you have your null reference there.
Without seeing the exact razor block it's hard to give you a more accurate place to look :-)
NullReferenceException on empty line in view
I'm experiencing something pretty when testing a simple Umbraco page. I get a null reference exception, but according to the stacktrace, the line triggering the exception has nothing but a curly bracket.
Here's the codeblock in question:
Has anyone experienced something like this, and figured out what is causing it ?
Hi Kristian,
So this is the "downfall" of razor. There is infact code behind in a razor view, in that at runtime (unless configured otherwise) the view is compiled. As a result errors, particularly null references, can be reported on incorrect lines.
The odds are, look for the next razor code in your file after the line being reported (e.g. something like
@object.dosomething.this
and you'll find you have your null reference there.Without seeing the exact razor block it's hard to give you a more accurate place to look :-)
Nik
is working on a reply...