Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

asp.net - What is wrong with this type of .aspx code?

I'm having one bear of a time trying to figure out why a legacy project won't compile for me; I get only one error, an "Object reference not set", which is usually straightforward to fix, but in this case it provides no detail as to even which file the problem appears in. See this for the initial question, with many updates.

I have a suspicion that the many Warnings, which say the same thing ("Object reference not set to an instance of an object") are behind the Error.

The problem is the code that is generating these warnings is not, as far as I can tell, problematic; but then again, I'm no ASP.NET expert, and certainly not when it comes to the VB side of things, to which I am an utter newbie.

2-clicking these warnings ("ASP.NET runtime error: Object reference not set to an instance of an object.") takes me to lines like this:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="yanceys._Default" title="Web Order Entry" %>

These occur in several folders beneath the Project - these folders have a Default.aspx file, beneath which is a Default.aspx.vb file.

They all look the same, except for what precedes the "._Default" in the Inherits element ("yanceys" below):

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="yanceys._Default" title="Web Order Entry" %>

<!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>Order Entry Login Page</title>
</head>
<body>
<form id="form1" runat="server">
    <div>
    </div>
</form>
</body>
</html>

And the Default.aspx.vb files are the same, too:

Namespace yanceys
    Partial Class _Default
        Inherits Page

        Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            Session("SelectedMenu") = "Home"
            Response.Redirect("../Login.aspx?MemberNo=042")
        End Sub
    End Class
End NameSpace

...except for the Namespace ("yanceys" above) and MemberNo ("042" above) which are unique for each Default.aspx.vb file.

What could be the problem? What could be the solution?

UPDATE

When I did a global search for "Namespace" to see what I might be able to prepend to "yanceys" to get it to work, the count of Warnings ballooned to one for each of this type of file, all of the same ilk ("ASP.NET runtime error: Object reference not set to an instance of an object."), all pointing to that same line as the culprit:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="yanceys._Default" title="Web Order Entry" %>

This makes me think if I can solve these Warnings, the Error (of the same stripe, namely, "Object reference not set to an instance of an object") will also be resolved.

UPDATE 2

Following T.S.'s suggestion, I opened VS (2013) as Admin, then File > Open Website...

The rebuild worked; the build gives me 1 error, as before, but a different one:

Error 1 It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS. C:MemberOrderEntryMembersOrderEntryMembersOrderEntryMobileweb.config 75

NOTE: Doing this also causes the Solution to be named "localhost_2030"; that seems odd to me...

UPDATE 3

In response to T.S.'s suggestion, I see no way to convert a file from Code File to Code-behind.

When I right-click the project, I see this:

enter image description here

...and when I right-click an individual .vb file I see this:

enter image description here

UPDATE 4

To perhaps be a little clearer, the Warning (and probably associated "blind" Error) appear like so in the Error List when I 2-click the Warning message:

enter image description here

...and the problematic file lives in a project folder as shown here:

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found this written by the cat with the indecisive surname, which sounded promising, so I closed VS, deleted the two *.suo files, reopened VS ("As Administrator") and then the project, tried Build > Rebuild Web Site, and got:

Error   1   compiler initialization failed unexpectedly: Project already has a reference to assembly System.Web.Extensions. A second reference to 'C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Web.Extensions.dll' cannot be added. vbc : Fatal

2-clicking the Error took me nowhere.

I thought, What now? Where is a second reference to System.Web.Extensions.dll attempting to be added, and how can I prevent that?

Meanwhile, the irritation of dealing with messages about TFS connections sent me on a detour down that path - to rid the project of all TFS vestiges. The answers here about deleting some files (*.vsssssssssccccc and such) and removing certain global sections from the .sln file not only cleared up that irritation, but also ended up, apparently, solving the other problems.

So some combination of the following:

Deleting the .suo files
Cleaning out the TFS files and sections
Running VS as Administrator

...got the project to a state where it actually finally runs! It seems like a mixture of magic and serendipity that these weird err msgs "just went away" as a result of these gyrations, but I guess I'll accept the fact that it at least finally works.

Note, too (I don't know why or how this fits into what happened), that something in those tweaks I made caused the "WEBSITE" menu in VS to change to "PROJECT"

UPDATE

And today the menu has changed back, from PROJECT to WEBSITE, but it still builds and runs, so I guess I'll just scratch my head in consternation and blithely continue on.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...