【问题标题】:Moving a legacy .NET App: "Object reference not set to an instance of an object."移动旧版 .NET 应用程序:“对象引用未设置为对象的实例。”
【发布时间】:2013-10-15 13:08:34
【问题描述】:

我在将基于 .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 2.0 安装了吗?
  • 99% 确定是这样,考虑到异常中的路径 `c:\Windows\Microsoft.NET\Framework\v2.0.50727`。
  • 我认为是的,在安装 IIS 7.0 期间,它是 v. 2.0.50727。但是,可能是错误的版本?我怎样才能找到要使用的正确 .NET 版本?
  • 忽略 .NET 2.0 版本,我认为这不是您异常的原因。那个版本号 - 2.0.50727 - 在我的电脑上是一样的。

标签: c# asp.net .net .net-2.0


【解决方案1】:

查看异常,它提到了一个ascx 文件。您能否查看 ASP.NET 应用程序的源代码并查看母版页中是否有 ascx 文件,或者至少在 aspx 页面中使用过?

看起来ascx 正在对一个对象做某事,而该对象为空。没有看到代码,这可能是对象为空的任何原因。

【讨论】:

  • 我添加了页面的代码;但错误显示“在第 0 行”......实际上我不知道真正的错误根源在哪里。另外,我不是 Microsoft 开发人员。
  • 看起来问题出在UC_ElencoViaggi.ascx。尝试从 aspx 页面中删除该 ascx 并再次尝试该站点。这次有用吗?删除使用 `
  • 不,它会产生另一个错误:Line 6: &lt;uc1:UC_ElencoViaggi ID="UC_ElencoViaggi1" runat="server" /&gt;。但是我认为这是页面的核心。
  • 我刚试了下,编译没有错误,但是页面没用,因为只显示母版页的骨架。我在ascx 页面中找到了这个参数:CodeBehind="UC_ElencoViaggi.ascx.cs"。但是文件UC_ElencoViaggi.ascx.cs 不存在。会不会是这个问题?
  • 不,您 100% 知道问题出在 UC_ElencoViaggi.ascx。所以现在,您需要打开文件UC_ElencoViaggi.ascx.cs 并找出问题所在。尝试注释掉一些代码,然后删除 cmets 以查看代码中断的位置。您可以发布UC_ElencoViaggi.ascx.cs 的源代码,但前提是您被允许这样做?如,源代码不是任何人的私有财产。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多