分析器错误消息:无法加载类型'MarketShare_Display'

时间:2015-01-27 21:57:31

标签: asp.net vb.net

我已经研究了好几天,但其他地方的建议都没有解决这个问题。该站点以经典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 

标记就像这样(下面)多年了,虽然我最近将CodeFile =更改为CodeBehind =进行&#34;转换为Web应用程序&#34;:

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

背景

此站点中的代码已在运行IIS 6.0的Windows 2003 Server上生产多年。它起初是一个ASP站点(&#34;经典ASP&#34;)并且在某些时候添加了使用ASP.NET的新功能(例如,此页面将数据库的结果集格式化为由Crystal Reports动态构建的PDF) 。

现在我尝试使用IIS 7.5在Windows 2008 R2上重新构建它。使用复制的源代码,我使用Visual Studio 2012 Update 4创建了一个新的Web项目。我在迁移报告后进行了各种小的更改。

现在,该网站的大部分都是经典的ASP,带有服务器端VBScript和客户端Javascript,它可以按预期工作,即使是SQL数据库访问和报告也是如此。

要点: 我导航到ASP.NET页面的几个地方如上所示我收到此消息 - &#34;无法加载类型...&#34;

修改:

从对象浏览器中,我注意到2个命名空间; MDS和MDS.MDS!从Project属性中,我清除了根命名空间,将程序集名称保留为MDS: greenshot of project properties now

我查看了其他.aspx文件(总共只有5个),调用&#34;转换为Web应用程序&#34;为每个并将Namespace MDS添加到每个CodeBehind文件。

现在相同的测试序列会产生不同的错误:

分析程序错误消息:&#39; MarketShare_Display&#39;这里不允许,因为它没有扩展类&System; Web.UI.Page&#39;。其余的错误与以前相同:

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 =&#34; MDS.MarketShare_Display&#34;确定错误消息再次改变(见下文)。因此,我将结束这一点并以不同的方式寻求整体解决方案。非常感谢。 new error message

1 个答案:

答案 0 :(得分:1)

运行时发生的could not load type的分析器错误(根据我的经验)通常是命名空间中的疏忽/冲突的结果。

运行应用程序时,解析器将尝试在aspx标记文件和程序集中的类型之间建立链接。因此,在这种情况下,解析器正在应用程序集中查找inherits=MarketShare_Display

<%@ Page Language="vb" AutoEventWireup="false" Inherits="MarketShare_Display" CodeBehind="MarketShare.aspx.vb" %>

注意:CodeBehind只是开发时间的VS项目链接。它在运行时没有任何意义。

但是MarketShare_Display只是一个类名而不是一个完全限定的类型名。在这种情况下,MarketShare_Display的实际FQTN将来自类代码文件中使用的命名空间与Project Properties&gt;中的任何名称空间的组合。 RootNamespace。

在VB中,类型的名称空间将是rootnamespace.classnamespace,在本例中为MDS.MDS,在rootnamespace为空之前。一旦rootnamesapce变为空白,则namepsace类型为MDS。

在C#中,类名称空间获胜,如果已定义,则使用rootnamespace。如果两者都提供,C#不会将两者结合起来。

因此,在这种情况下(rootnamespace为空)的FQTN为MDS.MarketShare_Display,但是inherits值使解析器只查找MarketShare_Display,因此找不到类型的异常。

另一个潜在的问题是你有部分类,一个是命名空间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是一个不同于MarketShare_Display的类。 (假设vb项目中的rootnamespace为空)。

通常情况下,如果你在两个部分中调用功能,你就会得到编译错误,因此它甚至不能运行但是如果由于某种原因你只有一个空的部分类,那么你可以浪费几分钟试图弄清楚为什么你会得到这些&#34;荒谬的&#34;解析器错误。