Why am I getting this System.NullReferenceException?

I get a strange error. I have the following foreground code:

<%@ Page Title="" Language="C#" MasterPageFile="~/nokernok/MasterPages/nokernok.Master" AutoEventWireup="true" CodeBehind="articleList.aspx.cs" Inherits="development.nokernok.articleList" %>
<%@ Register TagPrefix="EPiServer" Namespace="EPiServer.WebControls" Assembly="EPiServer" %>

<asp:Content ID="Content2" ContentPlaceHolderID="LeftContentPlaceHolder" runat="server">    
    <asp:Label ID="lblTest" runat="server" />    
</asp:Content>

And I have the following code:

using System;
using System.Web;
using EPiServer;
using EPiServer.Core;
using development.NaafLibrary;

namespace development.nokernok
{
    public partial class articleList : TemplatePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblTest.Text = "TEEEEEEEEEEEST";    
        }
    }
}

Constructor File:

namespace development.nokernok {
    public partial class articleList {        
       protected global::System.Web.UI.WebControls.Label lblTest;
    }
}

And I get this error message:

Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

[NullReferenceException: Object reference not set to an instance of an object.]
development.nokernok.articleList.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\naaf\nokernok\articleList.aspx.cs:17
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

I have other templates that work great. I just don't understand why I am getting this error here.

Update 1 :

I have added some more code.

+5
source share
3 answers

check if the associated .aspx.designer.cs file

protected global::System.Web.UI.WebControls.Label lblTest;
+3
source

Thank you for helping the guys.

Now I have worked. I deleted the file and created a new one. Then I added line by line.

, . , , .

+2

Is this a web application project (not a website project)? If yes (no), delete *.designer.cs, and then in the file’s context menu *.as*x(your page or control) →Convert to web application

+1
source

All Articles