Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VS 2015 allow attributes separated by spaces while VS 2017 does not?

Take the following simple code. The DoMyCode method has two attributes applied to it, with a space between the entries.

using System;

namespace AttributeSpaceTesting
{
    class Program
    {
        static void Main(string[] args) { }

        [Horse Cow]
        static void DoMyCode() { }
    }

    [AttributeUsage(AttributeTargets.Method)]
    class HorseAttribute : Attribute { }

    [AttributeUsage(AttributeTargets.Method)]
    class CowAttribute : Attribute { }
}

This was made in VS 2015 targeting .Net 4.6.

If you run this code in Visual Studio 2015 (update 3) it will compile and run with no errors or warnings.

However, running the exact same code in Visual Studio 2017 will produce the following exception:

Syntax error, ',' expected

I understand why this error happens. I expect that you would need commas between attribute items. In section 17.2 of the C# 5 specifications:

An attribute section consists of a pair of square brackets, which surround a comma-separated list of one or more attributes.

So why is this syntax legal in VS 2015?


For full context, I am experimenting with using VS 2017 on my team's unit test projects. I've noticed lines like this:

[Description(@"The Test Description")]
[TestCategory("Regression"), TestCategory("Module"), TestCategory("ModuleRegression") TestMethod]
public void TC_12345_VerifyTheThingWorks()

which cause syntax errors when compiled in the new Visual Studio system.

like image 943
gunr2171 Avatar asked Mar 08 '17 18:03

gunr2171


People also ask

Is it possible to use spaces in the tag?

apparently you can use spaces in the tag. see attached screen shot, the default entries for the Vessel Tag Info have spaces in the tags. there is a space befor and after the X, seperating the two text items. i want to duplicate this.

Can I install Visual Studio 2015 on top of vs 2013?

Yes. Visual Studio 2015 does not install on top of VS 2013, but is installed alongside VS 2013. You can however, try VS 2015 for free for 30 days, after which your license will expire. Additionally you can use Visual Studio 2015 Community for free.

Why can't I create a space in a tag using ACAD?

The first Problem is: Acad allow Spaces in Tag, not by create via Attdef, but by editing (properties palette f.e.). The second thing is: Thousends of other DWG and DXF writer allows it. Acad works well with that attdef /attribs, except the old Express command like ATTOUT or perhaps -ATTEDIT too.

How much disk space does Visual Studio take up?

If you chose to do a full installation though, Visual Studio is a pretty big product and will take over 30GB of disk space after installation and it installs a lot of third party software including the Android SDK, the Java Developer Kit, and the Windows and Android emulators.


1 Answers

Thanks to Hans Passant who shared this information.

It appears that this was indeed a bug with the roslyn compiler. It was reported in October of 2016, well after the last release of VS 2015 in June of the same year.

This fix made its way into Visual Studio 2017, which is why this syntax is properly reported as an error.

like image 93
gunr2171 Avatar answered Sep 30 '22 14:09

gunr2171