Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my IDE complaining about new syntax after I've installed Roslyn?

I'm using Visual Studio 2013 currently and I write this simple code:

class Program
{
    private static void Main(string[] args)
    {
        Console.WriteLine(string error = "Hello world!");
    }
}

Obviously this is not a valid C# code, but the weird part is even though I see two errors, the code is compiling and working fine:

enter image description here

I'm thinking that migth be relevant with Roslyn because I installed Roslyn User Preview and other extensions,but the project template I'm using is standart Console Application template.So, why this code is compiling even though there is three compiler errors? I tried this with VS 2012 and it doesn't compile.Is that a compiler bug, or will this be valid in next version of C# ?

Here is the error list I'm seeing in VS 2012:

enter image description here

But there is definitely no error in VS 2013.

Note: I'm not sure whether it's relevant or not but I'm also using the Resharper.

like image 367
Selman Genç Avatar asked Apr 09 '14 21:04

Selman Genç


2 Answers

Welcome to the future! These "declaration expressions" are being considered for the next version of C#, and if you're using the Roslyn preview you get to try them out early.

like image 107
Neal Gafter Avatar answered Sep 28 '22 09:09

Neal Gafter


In VS 2013 with Roslyn but without ReSharper, the code compiles fine and I don't see any errors or squigglies.

This is the expected behavior, since this proposed C# 6.0 feature is supported in the current Roslyn preview.

If I enable ReSharper, I start seeing the squigglies, but there are no errors in the Error List window and the code still compiles fine.

This is also the expected behavior, because the current version of R# doesn't have any support for C# 6.0 features (why would it?).

So, you see the squigglies from R#, but VS can work with the code just fine.

If you want to try out the proposed C# 6.0 features, I suggest you temporarily disable R#.

like image 45
svick Avatar answered Sep 28 '22 10:09

svick