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.
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
.
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.
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.