gpt4 book ai didi

c# - 为什么会出现此 System.NullReferenceException?

转载 作者:太空狗 更新时间:2023-10-29 23:11:21 24 4
gpt4 key购买 nike

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

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

我刚刚添加了一些代码。

最佳答案

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

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

关于c# - 为什么会出现此 System.NullReferenceException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3100152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com