为什么我会收到此 System.NullReferenceException?

发布于 2024-09-06 09:03:03 字数 2057 浏览 5 评论 0原文

我收到一个奇怪的错误。我有以下前端代码:

<%@ 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>

我有以下后端代码:

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";    
        }
    }
}

设计器文件:

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

我收到此错误消息:

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

我有其他工作正常的模板。 我只是不明白为什么我会在这里收到此错误。

更新 1

我刚刚添加了一些代码。

I'm getting a weird error. I have the following front-end 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 backend 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";    
        }
    }
}

Designer file:

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

And I get thiss 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 which works just fine.
I just can't understand why I'm getting this error here.

Update 1:

I just added some more code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我的影子我的梦 2024-09-13 09:03:03

检查相关的.aspx.designer.cs是否有

protected global::System.Web.UI.WebControls.Label lblTest;

check if related .aspx.designer.cs have

protected global::System.Web.UI.WebControls.Label lblTest;
秋千易 2024-09-13 09:03:03

谢谢你们的帮助。

我现在已经可以使用了。我删除了该文件并创建了一个新文件。然后我逐行添加。

我仍然不知道出了什么问题。看看代码,一切似乎与我开始时几乎一样。

Thanks for you help guys.

I got it working now. I deleted the file and created a new one. Then I added line by line.

I still don't know what went wrong. Looking at the code, it all seems pretty much the same as I started out with.

转身以后 2024-09-13 09:03:03

它是一个网络应用程序项目(不是网站项目)吗?如果是(否),请删除 *.designer.cs ,然后 - 在 *.as*x 文件(您的页面或控件)的上下文菜单中 -> 转换为网络应用程序

Is it a web app project (not a web site project)? If yes (no), delete *.designer.cs and after that - in the context menu of *.as*x file (your page or control) -> Convert to web application

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文