Nasty Const Bug in ASP.NET 5
Recently, Microsoft released some much-anticipated software including Visual Studio 2015 and .NET 4.6. This has not been without hiccups though: the guys at Stack Exchange identified a serious flaw in the new .NETâs RyuJIT compiler, which was promptly fixed by Microsoft.
And if, like me, you happen to be playing around with the prerelease technologies, youâre bound to run into other odd behaviour. Specifically, I ran into an issue where debugging information would stop working in an ASP .NET 5 Web Application. I posted a question on Stack Overflow about it before realising it was caused by the presence of a const.
To reproduce the issue, letâs create a new Web Application. In the template selector, weâll use one of the ASP .NET 5 Preview Templates:
Locate the Index() method in HomeController, and add some code involving a const:
public IActionResult Index()
{
const int x = 1;
ViewData["x"] = x;
return View();
}Put a breakpoint somewhere. Run the application, and youâll notice two things:
- If you hover over the constant, you wonât get any tooltip showing its value.
- If you try to get that information from the Immediate Window or watches, youâll get the following error:
error CS0648: '' is a type not supported by the language
In the above screenshot you canât see that my cursor is actually on x and Iâm not getting any intellisense, but you can see the message in the Immediate Window.
If we instead go to the About page, though, debugging tooltips work fine:
In fact, if you add some code in the Index() method (e.g. before the const is declared), youâll notice that you canât see the value of any variables or constants in the whole method. Other methods, however, are unaffected.
Let us now remove the const keyword and make x a variable instead:
There you go, it was the const keyword that messed up debugging information for the whole method. Removing it made everything work again.
I have no idea whatâs causing this bug, but itâs clearly in ASP .NET 5. Console applications do not have this problem, nor do ASP .NET web applications prior to version 5.
Update 2015.09.30: There seems to be an open issue about this, posted just a few days ago.
| Reference: | Nasty Const Bug in ASP.NET 5 from our NCG partner Daniel DAgostino at the Gigi Labs blog. |






