2010-07-01 49 views
2

有人可以解釋這個錯誤?錯誤創建控制vs2010主頁

錯誤創建控件 - 頭 未將對象引用設置爲對象的實例。

<%@ Page Title="" Language="C#" MasterPageFile="~/Controls/Master1.Master" 
AutoEventWireup="true" CodeBehind="GrupoUsuario.aspx.cs" Inherits="GrupoUsuario" %> 

<asp:Content ID="Content1" runat="server" contentplaceholderid="head"> 
</asp:Content> 

我覺得這是設計視圖中的visual studio 2010的bug。我不使用任何事件來操作OnInt()方法中的會話對象。 「PlaceHolderTopo」是Web用戶控件Topo.ascx中的佔位符。這是正常的工作。我在從母版頁繼承的頁面中的內容佔位符中沒有任何代碼,並且得到此錯誤。

下面是母版的代碼:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="PrincipalSeguranca.Master.cs" Inherits="PrincipalSeguranca" %> 
<%@ Register Src="Topo.ascx" TagName="Topo" TagPrefix="uc1" %> 
<%@ Register src="MenuAdmin.ascx" TagName="MenuAdmin" TagPrefix="uc2" %> 
<%@ Register src="Rodape.ascx" tagname="Rodape" tagprefix="uc3" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Sistema</title> 
    <script language="jscript" type="text/javascript" src="Scripts/Geral.js"></script> 
    <link rel="shortcut icon" href="../layout/ico/favicon.ico" type="image/x-icon" /> 
    <link rel="stylesheet" href="../layout/css/styles.css" type="text/css" /> 
    <link href="../layout/css/menu_tabbed.css" rel="stylesheet" type="text/css" /> 
    <link rel="stylesheet" href="../layout/css/contents.css" type="text/css" /> 
</head> 

<body> 

    <form id="form1" ClientInstanceName="form1" runat="server"> 
    <uc1:Topo ID="Topo1" runat="server" /> 
    <div id="corpo"> 
     <asp:ContentPlaceHolder ID="head" runat="server"> 
     </asp:ContentPlaceHolder> 
    </div> 
    <div id="rodape"> 
     <uc3:Rodape ID="Rodape1" runat="server" /> 
    </div> 
    </form> 
</body> 
</html> 

回答

5

你必須在設計時你Rodape控件中的錯誤。

當您在設計視圖中打開頁面時,它會在Visual Studio的過程中創建自定義控件的實例。由於您的網站並未實際運行,因此您的控件中的代碼可能正在訪問尚未初始化的靜態成員。

您應該啓動Visual Studio的第二個副本,將它的調試器附加到第一個副本,從Debug菜單中設置Break on All Exceptions,並找到您的錯誤。

+0

謝謝你,你救了我的生命!我在接口項目引用的其他項目中發現一個錯誤,並將該錯誤引發到接口。我解決了這個問題。 謝謝你的男人。 asp.net論壇和MSDN論壇不幫助我。在stackoverflow的第一篇文章解決了我的問題。這個網站是最好的幫助開發者。 – Devman 2010-07-01 16:17:25