Frage

I'm not sure if this is a bug or something else.

I create a new Web Application project in VS2010. In the project, I create a new class (Class1), with the following contents:

public void Test()
{
    var s = "Hello";
    Console.WriteLine(s);
}

When I hover my mouse over s in the Console.WriteLine(s) line, a popup appears showing (local variable) string s. Great, just as I expect.

Correctly showing s to be of type string

Now, I add an App_Code folder to the project. Inside it, I again create a new class (Class2), with the exact same contents (except the class name). Now, when I hover s, it shows (local variable) var s.

Incorrectly showing s to be of type var

Why is it showing var in stead of string? Is this a bug? Can you reproduce this behavior?

It's even worse. If I move Class2.cs from the App_Code folder to the root of the project, VS2010 still doesn't show the type. Even after restarting VS2010 and reopening the project, VS2010 will show the correct type in Class1 but not in Class2. I've also tried deleting the .suo and .csproj.user files, but still no difference. Apparently VS2010 caches this information somewhere.

War es hilfreich?

Lösung

The App_Code directory is a special directory for Web Site projects.

In Web Application projects, code placed inside the App_Code directory is ignored by VS.

I noticed this behavior when migrating a Web Site to a Web Application project.

Andere Tipps

I think this is happening due to App_Code folder. Because App_Code folder compiled at run time. As MSDN describe here.

In a Web site project, you can store source code in the App_Code folder, and it will be automatically compiled at run time. The resulting assembly is accessible to any other code in the Web application. The App_Code folder therefore works much like the Bin folder, except that you can store source code in it instead of compiled code. The App_Code folder and its special status in an ASP.NET Web application makes it possible to create custom classes and other source-code-only files and use them in your Web application without having to compile them independently.

Here is MSDN link

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top