开发者

Compile errors on deployed web application, but not in the IDE

开发者 https://www.devze.com 2023-02-01 16:06 出处:网络
In my deployed web application I am getting the following error: CS0103: The name \'releaseLionButton_Click\' does

In my deployed web application I am getting the following error:

CS0103: The name 'releaseLionButton_Click' does not exist in the current context

It identifies this as the offending line:

<asp:Button ID="releaseLionButton" runat="server" 
            Text="Release the Lion!"
            OnClick="releaseLionButton_Click"></asp:Button>

In the code-behind file, I have the following code:

internal void releaseLionButton_Click(object sender, EventArgs e)
{
    if (selectedLionCage != null && selectedLionCage.DoorState == DoorState.Closed)
        selectedLionCage.OpenDoor();
}

Now I can make this error go away by changing internal to protected, which makes sense, since the ASPX page says it "Interits" from the Page class defined in the code-behind file.

That's all fine.

What I don't understand is why the program works with internal when I run the program in the IDE on my local machine.

I don't want the testers to run into a hundred such stupid errors, and I don't want to do the test deployment paperwork for a hundred slightly-different versions of the program.

I want it to not work in the IDE if it's not going to work for real!

So here's my question:

How can I get the local version in the IDE to generate all of the compilation errors that the deployed version is going to experience?

More information to distract you from the real problem开发者_如何学编程:

The Target Framework for the application is ".NET Framework 3.5". It must be this because it references System.DirectoryServices.AccountManagement.

The error page on the test machine, in contrast, says "Version Information: Microsoft .NET Framework Version:2.0.50727.4206; ASP.NET Version:2.0.50727.4209".

And yet the Directory Services Account Management code works perfectly on the test machine. I don't know what's going on there either.

Other, similar problems that I am experiencing

This is an older application that I am maintaining, and it will occasionally give me a long list of validation warnings for some random ASPX file. I fix all of these even though the code still works, because I like my code to be clean and pretty. I have not yet found a way to generate the validation warnings on purpose for all files or for any particular file.

Sometimes when I refactor the code (such as by changing a variable name) it will warn me that the code does not currently compile, so the refactoring may not work. And yet I cannot get the IDE to tell me why it thinks the code won't compile. It still runs perfectly, and no errors or warnings appear in the Error List! Other times, with no pattern that I have discovered, it will not display the warning message during a refactoring.

UPDATE regarding the validation of ASPX files

When answering another question it was pointed out to me that validation for ASPX files will work if the "Show live semantic errors" option is enabled for the C# editor. This explains why I was having problems that nobody else seemed to be having.


The problem is, if you have a traditional asp.net website with .aspx and .cs/vb codebehinds, is that there are actually two different assemblies involved. Your codebehind compiles to one assembly, and IIS will take the .aspx and compile it dynamically to another assembly. When you mark something as internal you define an assembly boundary, and thus the dynamic aspx assembly can't reference the internal member in the codebehind assembly.

Now, as to why it doesn't work like that in VS's webserver I don't know as I'm not familiar with the particulars of it. However, what you can do is just set up your website in IIS on your machine. That way it will behave exactly like the "production" version.

If you're worried about debugging it, it's no problem, run Visual Studio with administrative rights, and when a server error on your machine occurs, attach to the w3wp.exe using Visual Studio and it'll figure it out and break on the error.


I would guess you are not compiling your web projects in your solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消