aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

`const` results in error CS0648: '' is a type not supported by the language

Open staff0rd opened this issue 11 years ago • 7 comments

REPRO

  1. Open VS2015 (Windows 10, ASP.NET 5 Beta 7)
  2. Click File > New > Project > Web > Console Application (Package) > Ok
  3. Edit Program.cs to reflect code snippet below.
  4. Add a breakkpoint just after Console.WriteLine(a);
  5. Run the project
  6. Right-click variables a and b click 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

  1. The value of a is written correctly to Console
  2. Removing const from the snippet reverts to EXPECTED bevahiour

staff0rd avatar Sep 27 '15 06:09 staff0rd

+1 Just discovered this is occuring in Xunit tests as well. Cannot view any local variables in scope while debugging if "const" is involved

Sharpiro avatar Sep 27 '15 23:09 Sharpiro

@barrytang looks like maybe something with the debugger or Roslyn is changed? Do you know a contact there?

Eilon avatar Sep 28 '15 22:09 Eilon

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/

dandago avatar Sep 30 '15 19:09 dandago

I contacted the Roslyn team to have them take a look at this.

Eilon avatar Sep 30 '15 19:09 Eilon

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.

halverson-dev avatar Oct 01 '15 04:10 halverson-dev

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.

halverson-dev avatar Oct 02 '15 23:10 halverson-dev

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!

Eilon avatar Oct 03 '15 05:10 Eilon