1

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:\MemberOrderEntry\MembersOrderEntry\MembersOrderEntry\Mobile\web.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

Koder101
  • 844
  • 15
  • 28
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    Copy your pages into a new project one item at a time until you isolate the error. – mason Dec 06 '16 at 01:27
  • 1
    With vb, I believe, just because you have `namespace yanceys ... Partial Class _Default...` it doesn't mean that namespace indeed `yanceys`. The base namespace is set in the project file itself. so the namespace can really be `Something.else.yanceys` – T.S. Dec 06 '16 at 02:43
  • @mason: I did try that, but that one has even more errors. I return to the legacy one because there is only one. In fact, I get, "Maximum number of errors has been exceeded" – B. Clay Shannon-B. Crow Raven Dec 06 '16 at 16:15
  • @T.S.: There is no project file (if you mean *.vbproj) for this project; it has the following types: master, ico, master.vb, aspx, aspx.vb, as well as vwd.webinfo, web.config, and website.publishproj – B. Clay Shannon-B. Crow Raven Dec 06 '16 at 16:20
  • 1
    Ah - you have "CodeFile" - it means you're using Web Site Project - WSP. You don't have proj file. One thing you can try and sometimes it affects build - how you open your website project. Do this - Open VS as admin, go to `file-open-website` - open it this way and try to build. BTW, this format is no longer supported in VS15. It is good idea to get rid of this by creating new Web Site Application, WSA project, use "Add Existing file" feature to add all the pages and then use menu in solution explorer to convert `CodeFile`(s) to `CodeBehind`. Now, you will have nice namespace structure – T.S. Dec 06 '16 at 16:33
  • 1
    Also, VS13 has some quirks to it. In my office we stopped using it because it exhibited different behavior. We use either 12 or 15. You can try building your site using `Aspnet_compiler.exe` to see if this is issue related to VS acting or it is really problem with website – T.S. Dec 06 '16 at 16:35
  • @T.S.: Thanks; I tried that - opened VS 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:\MemberOrderEntry\MembersOrderEntry\MembersOrderEntry\Mobile\web.config 75 – B. Clay Shannon-B. Crow Raven Dec 06 '16 at 16:39
  • 1
    Fix your web config - google for this one – T.S. Dec 06 '16 at 16:43
  • also, how do you run your website? Suggestion - create virtual directory (your project dir) in IIS, config APP pool, permissions. And when you change the code, don't forget to stop pool, delete temp asp.net files. There are few things to take care of there – T.S. Dec 06 '16 at 16:51
  • @T.S.: " use menu in solution explorer to convert CodeFile(s) to CodeBehind" I'm not seeing this option; perhaps it's not available in VS 2013? – B. Clay Shannon-B. Crow Raven Dec 06 '16 at 17:05
  • @T.S.: I see no "Convert" option either way; see Update 3. – B. Clay Shannon-B. Crow Raven Dec 06 '16 at 17:09
  • Here is **exactly** what I am talking about. Come on! Google! http://peterkellner.net/2012/12/30/converting-asp-net-wsp-web-site-projects-to-wap-web-application-projects-with-vs2012/ – T.S. Dec 06 '16 at 17:14
  • No, following the steps you provided did not create a proj file. I guess I will have to create a new project and see what happens... – B. Clay Shannon-B. Crow Raven Dec 06 '16 at 17:15
  • @T.S.: What exactly do you mean by "It is good idea to get rid of this by creating new Web Site Application, WSA project" - is a "WSA" project created via File > New Website, WebForms, or how? – B. Clay Shannon-B. Crow Raven Dec 07 '16 at 00:30
  • 1
    My friend, all information is available by Microsoft. Do you use MSDN? Here is what you need to read for this issue https://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx. Now, in 2 words, if you need to be able to change content/compile without stopping your site you need WSP. You can also use both, VB and c# simultaneously with that Other than that, there it no damn good reason to use WSP. It is headache and Microsoft discontinued it. WAP - web application project mainly differentiates by compiling all code under single DLL and better manageability. WSP compiled by aspnet_compiler – T.S. Dec 07 '16 at 02:38
  • 1
    WAP compiled by msbuild. And it acts in DEV jusl like any other dll or exe project. It is really recommended in 99% of cases to use WAPs. WAP and WSP are just project templates. Read the link! – T.S. Dec 07 '16 at 02:40
  • @T.S.: I understand that WAP is better than WAS for new projects, but my dilemma is to get this existing project compiling, and if it was created as a WSP, aren't I better off going that route? – B. Clay Shannon-B. Crow Raven Dec 07 '16 at 17:07
  • 1
    for the last 4 years our UI is 2 13 year old WSP projects that we keep maintaining. We know, this is crap but we have no choice because we in fact do have custom inclusions. For you - YOU need to answer this question. I didn't say that *under no circumstance should you use WSP*. I say, see if you need it, calculate conversion effort, project benefits... Get it compiled. Fix web.config. Looks like you're near your goal – T.S. Dec 07 '16 at 17:13
  • @T.S.: So close, and yet so far. – B. Clay Shannon-B. Crow Raven Dec 07 '16 at 17:16
  • I disagree that I am close, because I still have this "Object reference not set" issue, to which I have no clue what the solution is. – B. Clay Shannon-B. Crow Raven Dec 07 '16 at 17:25

1 Answers1

0

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 Assemblies\Microsoft\Framework\v3.5\System.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.

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862