移动旧版 .NET 应用:“对象引用未设置为对象的实例

本文关键字:设置 对象 实例 对象引用 NET 应用 移动 | 更新日期: 2023-09-27 18:35:21

我在将基于 .NET 2.0 并用 C# 编写的旧版 Web 应用程序移动到新的 Windows 2012 Foundation Server 时遇到了问题。IIS 7.0 已在 ASP.NET 经典模式下配置。

几乎所有页面都显示以下错误。

我想知道生成此错误的源代码部分是什么,但消息显示[No relevant source lines].

你有什么想法吗?

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
    [No relevant source lines]  
    Source File: c:'Windows'Microsoft.NET'Framework'v2.0.50727'Temporary ASP.NET Files'root'813bde8d'3a1aaa6a'App_Web_uc_elencoviaggi.ascx.572aee0e.phamg6cd.0.cs    Line: 0
    Stack Trace:  
            [NullReferenceException: Object reference not set to an instance of an object.]

 Makr.UI.PagamentiDataContext..ctor() +28
   Makr.UI.Viaggi.UC_ElencoViaggi..ctor() +26
   ASP.viaggi_uc_elencoviaggi_ascx..ctor() in c:'Windows'Microsoft.NET'Framework'v2.0.50727'Temporary ASP.NET Files'root'813bde8d'3a1aaa6a'App_Web_uc_elencoviaggi.ascx.572aee0e.phamg6cd.0.cs:0
   ASP.amministrazione_elencoviaggi_aspx.__BuildControlUC_ElencoViaggi1() in c:'inetpub'wwwroot'WebApp_Makr_Contabilita'Amministrazione'ElencoViaggi.aspx:6
   ASP.amministrazione_elencoviaggi_aspx.__BuildControlContent2(Control __ctrl) in c:'inetpub'wwwroot'WebApp_Makr_Contabilita'Amministrazione'ElencoViaggi.aspx:5
   System.Web.UI.CompiledTemplateBuilder.InstantiateIn(Control container) +12
   ASP.master_amministrazione_master.__BuildControlContentPlaceHolder1() in c:'inetpub'wwwroot'WebApp_Makr_Contabilita'Master'Amministrazione.Master:150
   ASP.master_amministrazione_master.__BuildControlform1() in c:'inetpub'wwwroot'WebApp_Makr_Contabilita'Master'Amministrazione.Master:13
   ASP.master_amministrazione_master.__BuildControlTree(master_amministrazione_master __ctrl) in c:'inetpub'wwwroot'WebApp_Makr_Contabilita'Master'Amministrazione.Master:1
   ASP.master_amministrazione_master.FrameworkInitialize() in c:'Windows'Microsoft.NET'Framework'v2.0.50727'Temporary ASP.NET Files'root'813bde8d'3a1aaa6a'App_Web_9f0g2exr.0.cs:0
   System.Web.UI.UserControl.InitializeAsUserControlInternal() +35
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +8696687
   System.Web.UI.Page.get_Master() +51
   System.Web.UI.Page.ApplyMasterPage() +15
   System.Web.UI.Page.PerformPreInit() +45
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282

这是页面的代码:

<%@ Page Language="C#" EnableEventValidation="false" Theme="default" MasterPageFile="~/Master/Amministrazione.Master" AutoEventWireup="true" CodeBehind="ElencoViaggi.aspx.cs" Inherits="Makr.UI.Amministrazione.ElencoViaggi" Title="Untitled Page" %>
<%@ Register src="../Viaggi/UC_ElencoViaggi.ascx" tagname="UC_ElencoViaggi" tagprefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <uc1:UC_ElencoViaggi ID="UC_ElencoViaggi1" runat="server" />
</asp:Content>

移动旧版 .NET 应用:“对象引用未设置为对象的实例

查看异常,它提到了一个ascx文件。是否可以查看 ASP.NET 应用的源代码,并查看母版页中是否使用了ascx文件,或者至少在aspx页中使用了该文件?

看起来ascx正在对一个对象执行某些操作,并且该对象为 null。如果没有看到代码,这可能是对象为 null 的任何原因。