aspnet / Tooling

Issue tracker and info on Visual Studio tooling for ASP.NET
Other
256 stars 123 forks source link

VS2017 IDE will not accept decimal constants as attribute arguments (CS0181, CS0182) #971

Closed ericwj closed 7 years ago

ericwj commented 7 years ago

Declaring a decimal typed argument to an attribute constructor in VS 2017 will produce CS0181. Providing a decimal typed argument to an attribute constructor that takes say object in VS 2017 will produce CS0182.

In both cases, building from the command line will work.

using System;

class DecimalAttribute : Attribute
{
    public DecimalAttribute(decimal value) { }
}
class AnyAttribute : Attribute
{
    public AnyAttribute(object value) { }
}
class Program
{
    // 1>Program.cs(14,3,14,5): error CS0181: Attribute constructor parameter 'value' has type 'decimal', which is not a valid attribute parameter type
    [Decimal(123m)] public int CS0181 { get; set; }
    // 1>Program.cs(15,7,15,11): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
    [Any(123m)] public int CS0182 { get; set; }
}
davkean commented 7 years ago

This issue was moved to dotnet/roslyn#16898