这种类型的 .aspx 代码有什么问题? [英] What is wrong with this type of .aspx code?

查看:16
本文介绍了这种类型的 .aspx 代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段时间想弄清楚为什么遗留项目不能为我编译;我只收到一个错误,即未设置对象引用",这通常很容易修复,但在这种情况下,它没有提供有关问题出现在哪个文件中的详细信息.请参阅

...当我右键单击单个 .vb 文件时,我看到:

更新 4

也许更清楚一点,当我双击警告消息时,警告(以及可能相关联的盲"错误)在错误列表中显示如下:

...并且有问题的文件位于项目文件夹中,如下所示:

解决方案

我发现 这个 是优柔寡断的姓猫写的,听起来很有希望,所以我关闭了VS,删除了两个*.suo文件,重新打开VS(作为管理员")然后是项目,尝试构建>重建网站,并得到:

错误 1 ​​编译器初始化意外失败:项目已引用程序集 System.Web.Extensions.无法添加对C:Program Files (x86)Reference AssembliesMicrosoftFrameworkv3.5System.Web.Extensions.dll"的第二个引用.vbc : 致命

2 次单击错误使我无处可去.

我想,现在怎么办?尝试添加 System.Web.Extensions.dll 的第二个引用在哪里,我该如何防止?

与此同时,处理有关 TFS 连接的消息的刺激让我绕道而行 - 消除所有 TFS 痕迹的项目.答案这里关于删除一些文件(*.vssssssssscccc 等)和删除某些全局.sln 文件中的部分不仅消除了这种烦恼,而且显然还解决了其他问题.

以下的一些组合:

删除.suo文件清除 TFS 文件和部分以管理员身份运行 VS

...使项目达到最终实际运行的状态!由于这些旋转,这些奇怪的错误消息消失了",这似乎是魔法和意外的混合,但我想我会接受它至少最终起作用的事实.

也请注意(我不知道为什么或如何适应发生的事情),我所做的调整中的某些内容导致 VS 中的网站"菜单更改为项目"

更新

今天菜单已经返回,从 PROJECT 到 WEBSITE,但它仍然可以构建和运行,所以我想我会惊愕地挠挠头,然后继续愉快地继续.

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:

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

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:

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

解决方案

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.

这篇关于这种类型的 .aspx 代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆