Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
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.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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 2016, well after the last VS 2015 release in June of the same year.

This fix made its way to Visual Studio 2017, so this syntax is correctly reported as an error.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda