`const` results in error CS0648: '' is a type not supported by the language
REPRO
- Open VS2015 (Windows 10, ASP.NET 5 Beta 7)
- Click File > New > Project > Web > Console Application (Package) > Ok
- Edit
Program.csto reflect code snippet below. - Add a breakkpoint just after
Console.WriteLine(a); - Run the project
- Right-click variables
aandbclick Add Watch
CODE
public void Main(string[] args)
{
const int a = 3;
int b = 4;
Console.WriteLine(a);
}
EXPECTED
Watch window displays values for variables a and b
ACTUAL
Watch window Value column for variables a and b displays:
error CS0648: '' is a type not supported by the language
NOTES
- The value of
ais written correctly to Console - Removing
constfrom the snippet reverts to EXPECTED bevahiour
+1 Just discovered this is occuring in Xunit tests as well. Cannot view any local variables in scope while debugging if "const" is involved
@barrytang looks like maybe something with the debugger or Roslyn is changed? Do you know a contact there?
I ran into this a few weeks ago, and wrote a blog post with some detail yesterday: http://gigi.nullneuron.net/gigilabs/nasty-const-bug-in-asp-net-5/
I contacted the Roslyn team to have them take a look at this.
Since constants aren't actually locals (they're just inline values in the emitted IL), we have to retrieve their name/value/type from the .pdb. It seems that the low-level API we use for doing this (ISymUnmanagedConstant.GetSignature) is always returning a zero-length array on CoreClr.
I should be able to make the watch for b work despite this, but we'll need a fix from the core debugger to show the value of a. I'll follow up with the folks who own the symreader and post back when I know more.
I have a PR out to ignore the const local in this case (enables you to at least inspect the other locals in that scope): https://github.com/dotnet/roslyn/pull/5658
I've also opened an internal bug for the core debugger to figure out why reading the signature of a const isn't supported here.
This is now being tracked on the Roslyn GitHub org and also in an internal MSFT bug database, so I'm closing this out. Thanks, everyone!