解析器错误消息:无法加载类型 'MarketShare_Display'
Parser Error Message: Could not load type 'MarketShare_Display'
我已经为此研究了好几天,但是 none 其他地方提出的建议已经解决了这个问题。该站点以 classic ASP 开始,运行正常,直到导航到需要 ASP.NET 的页面:
Server Error in '/MDS' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Source Error:
Line 1: <%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 3: <html>
Source File: /mds/Out/MarketShare.aspx Line: 1
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5483
标记多年来一直是这样(如下),尽管我最近在执行 "Convert to Web Application" 时将 CodeFile= 更改为 CodeBehind=:
<%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1" />
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"/>
<meta name="vs_defaultClientScript" content="JavaScript"/>
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5" />
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 296px; POSITION: absolute; TOP: 168px"
runat="server"></asp:DataGrid>
</form>
</body>
</html>
MarketShare.aspx.vb 文件如下:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb.OleDbConnection
Imports MDS.Classes
Namespace MDS
Partial Class MarketShare_Display
Inherits System.Web.UI.Page
Private oMsg As String
Private oRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim oSubReportHeading As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim oSubReportFooter As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim dsSubReport As New DataSet 'we bind this to oSubReportFooter if needed
Private oUtil As New CommonFormatter
Private oHMDA As New HMDAFormatter
Private oCR As New MyCrystalCommon
' Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objDataSet As DataSet = QueryDataBase()
If oUtil.HMDAData() Then
oRpt.Load(HttpContext.Current.Server.MapPath("./Crystal_RPTs/Report_HMDA_Marketshare.rpt"))
Else
oRpt.Load(HttpContext.Current.Server.MapPath("./Crystal_RPTs/Report_CONV_All_Detail.rpt"))
End If
' etcetera...
背景:
此站点中的代码已在 Windows 2003 Server 运行 IIS 6.0 上投入生产多年。它最初是一个 ASP 站点 ("classic ASP"),在某些时候添加了使用 ASP.NET 的新功能(例如,此页面将数据库中的结果集格式化为由 Crystal 报道)。
现在我尝试使用 IIS 7.5 在 Windows 2008 R2 上重新构建它。使用复制的源代码,我使用 Visual Studio 2012 Update 4 创建了一个新的 Web 项目。在迁移报告之后,我需要进行各种小的更改。
现在网站的大部分内容是 classic ASP,带有服务器端 VBScript 和客户端 Javascript,即使 SQL 数据库访问也能正常工作和报告。
总结:
如上所示,我导航到 ASP.NET 页面的几个地方收到此消息 - "unable to load type ..."
编辑:
在对象浏览器中,我注意到 2 个名称空间; MDS 和 MDS.MDS !从项目属性中,我清除了根命名空间,将程序集名称保留为 MDS:
我查看了其他 .aspx 文件(总共只有 5 个),为每个文件调用 "Convert to Web Application" 并将命名空间 MDS 添加到每个 CodeBehind 文件。
现在相同的测试序列给出了不同的错误:
解析器错误消息:此处不允许 'MarketShare_Display' 因为它不扩展 class 'System.Web.UI.Page'. 其余错误是和以前一样:
Source Error:
Line 1: <%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 3: <html>
Source File: /mds/Out/MarketShare.aspx Line: 1
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5483
第二次编辑:
我将其更改为 Inherits="MDS.MarketShare_Display" 并且果然错误消息再次更改(见下文)。因此,我将关闭它并以不同的方式寻求整体解决方案。非常感谢。
发生在 运行 上的 could not load type
的解析器错误(根据我的经验)通常是命名空间中 oversight/conflict 的结果。
当应用程序 运行 时,解析器将尝试在 aspx 标记文件和程序集中的类型之间建立链接。所以在这种情况下,解析器在应用程序程序集中寻找 inherits=MarketShare_Display
。
<%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
注意:CodeBehind 只是开发时的 VS 项目链接。在 运行 时间没有任何意义。
然而 MarketShare_Display
只是一个 class 名称,而不是完全限定的类型名称。在这种情况下,MarketShare_Display
的实际 FQTN 将来自 class 代码文件中使用的命名空间和项目属性 > RootNamespace 中的任何内容的组合。
在 VB 中,类型的命名空间将是 rootnamespace.classnamespace,在本例中是 MDS.MDS,然后根命名空间变为空白。一旦 rootnamesapce 被设为空白,type namepsace 就是 MDS。
在 C# 中,如果定义了 class 命名空间,则使用 root 命名空间。如果两者都提供,C# 不会将两者结合起来。
所以在这种情况下(根命名空间为空)的 FQTN 是 MDS.MarketShare_Display
但继承值让解析器只查找 MarketShare_Display
因此类型未找到异常。
另一个潜在问题是当您有部分 classes 时,一次是命名空间 MDS,另一次是空白。所以如果你有
Namespace MDS
Partial Class MarketShare_Display
Inherits System.Web.UI.Page
End Class
End Namespace
Partial Class MarketShare_Display
'' other functionality here
End Class
在这种情况下,解析器会找到类型 MarketShare_Display
,但当然它不会从 System.Web.Ui.Page 继承,因为 MDS.MarketShare_Display
与 class 不同 MarketShare_Display
。 (假设 rootnamespace 在 vb 项目中为空)。
通常情况下,如果你在两个部分中调用功能,你会得到一个编译错误,所以它甚至不会 运行 但如果出于某种原因你只有一个空的部分 class那么您可以花几分钟时间弄清楚为什么会出现这些 "absurd" 解析器错误。
我已经为此研究了好几天,但是 none 其他地方提出的建议已经解决了这个问题。该站点以 classic ASP 开始,运行正常,直到导航到需要 ASP.NET 的页面:
Server Error in '/MDS' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Source Error:
Line 1: <%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 3: <html>
Source File: /mds/Out/MarketShare.aspx Line: 1
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5483
标记多年来一直是这样(如下),尽管我最近在执行 "Convert to Web Application" 时将 CodeFile= 更改为 CodeBehind=:
<%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1" />
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"/>
<meta name="vs_defaultClientScript" content="JavaScript"/>
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5" />
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 296px; POSITION: absolute; TOP: 168px"
runat="server"></asp:DataGrid>
</form>
</body>
</html>
MarketShare.aspx.vb 文件如下:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb.OleDbConnection
Imports MDS.Classes
Namespace MDS
Partial Class MarketShare_Display
Inherits System.Web.UI.Page
Private oMsg As String
Private oRpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim oSubReportHeading As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim oSubReportFooter As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim dsSubReport As New DataSet 'we bind this to oSubReportFooter if needed
Private oUtil As New CommonFormatter
Private oHMDA As New HMDAFormatter
Private oCR As New MyCrystalCommon
' Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objDataSet As DataSet = QueryDataBase()
If oUtil.HMDAData() Then
oRpt.Load(HttpContext.Current.Server.MapPath("./Crystal_RPTs/Report_HMDA_Marketshare.rpt"))
Else
oRpt.Load(HttpContext.Current.Server.MapPath("./Crystal_RPTs/Report_CONV_All_Detail.rpt"))
End If
' etcetera...
背景:
此站点中的代码已在 Windows 2003 Server 运行 IIS 6.0 上投入生产多年。它最初是一个 ASP 站点 ("classic ASP"),在某些时候添加了使用 ASP.NET 的新功能(例如,此页面将数据库中的结果集格式化为由 Crystal 报道)。
现在我尝试使用 IIS 7.5 在 Windows 2008 R2 上重新构建它。使用复制的源代码,我使用 Visual Studio 2012 Update 4 创建了一个新的 Web 项目。在迁移报告之后,我需要进行各种小的更改。
现在网站的大部分内容是 classic ASP,带有服务器端 VBScript 和客户端 Javascript,即使 SQL 数据库访问也能正常工作和报告。
总结: 如上所示,我导航到 ASP.NET 页面的几个地方收到此消息 - "unable to load type ..."
编辑:
在对象浏览器中,我注意到 2 个名称空间; MDS 和 MDS.MDS !从项目属性中,我清除了根命名空间,将程序集名称保留为 MDS:
我查看了其他 .aspx 文件(总共只有 5 个),为每个文件调用 "Convert to Web Application" 并将命名空间 MDS 添加到每个 CodeBehind 文件。
现在相同的测试序列给出了不同的错误:
解析器错误消息:此处不允许 'MarketShare_Display' 因为它不扩展 class 'System.Web.UI.Page'. 其余错误是和以前一样:
Source Error:
Line 1: <%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
Line 2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
Line 3: <html>
Source File: /mds/Out/MarketShare.aspx Line: 1
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5483
第二次编辑:
我将其更改为 Inherits="MDS.MarketShare_Display" 并且果然错误消息再次更改(见下文)。因此,我将关闭它并以不同的方式寻求整体解决方案。非常感谢。
发生在 运行 上的 could not load type
的解析器错误(根据我的经验)通常是命名空间中 oversight/conflict 的结果。
当应用程序 运行 时,解析器将尝试在 aspx 标记文件和程序集中的类型之间建立链接。所以在这种情况下,解析器在应用程序程序集中寻找 inherits=MarketShare_Display
。
<%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>
注意:CodeBehind 只是开发时的 VS 项目链接。在 运行 时间没有任何意义。
然而 MarketShare_Display
只是一个 class 名称,而不是完全限定的类型名称。在这种情况下,MarketShare_Display
的实际 FQTN 将来自 class 代码文件中使用的命名空间和项目属性 > RootNamespace 中的任何内容的组合。
在 VB 中,类型的命名空间将是 rootnamespace.classnamespace,在本例中是 MDS.MDS,然后根命名空间变为空白。一旦 rootnamesapce 被设为空白,type namepsace 就是 MDS。
在 C# 中,如果定义了 class 命名空间,则使用 root 命名空间。如果两者都提供,C# 不会将两者结合起来。
所以在这种情况下(根命名空间为空)的 FQTN 是 MDS.MarketShare_Display
但继承值让解析器只查找 MarketShare_Display
因此类型未找到异常。
另一个潜在问题是当您有部分 classes 时,一次是命名空间 MDS,另一次是空白。所以如果你有
Namespace MDS
Partial Class MarketShare_Display
Inherits System.Web.UI.Page
End Class
End Namespace
Partial Class MarketShare_Display
'' other functionality here
End Class
在这种情况下,解析器会找到类型 MarketShare_Display
,但当然它不会从 System.Web.Ui.Page 继承,因为 MDS.MarketShare_Display
与 class 不同 MarketShare_Display
。 (假设 rootnamespace 在 vb 项目中为空)。
通常情况下,如果你在两个部分中调用功能,你会得到一个编译错误,所以它甚至不会 运行 但如果出于某种原因你只有一个空的部分 class那么您可以花几分钟时间弄清楚为什么会出现这些 "absurd" 解析器错误。