Bug 3550 - Decimal constant gives invalid CS0182
Summary: Decimal constant gives invalid CS0182
Status: RESOLVED INVALID
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Other Other
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2012-02-20 10:40 UTC by Alexey Pelykh
Modified: 2012-02-20 12:00 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Alexey Pelykh 2012-02-20 10:40:42 UTC
Description of Problem:
In class, I have property that has attribute (from nHibernate) that accepts decimal as a parameter of constructor ( DecimalMinAttribute(decimal value) ). Following code in my class generates invalid CS0182 error, while same code compiles fine in Microsoft compiler:

public class entity
{
//...
[DecimalMin(0m)]
public virtual decimal CashlessAdditionalPercentToOfficialRate { get; set; }
//...
}


Actual Results:
CS0182 error

Expected Results:
Compiled executable

How often does this happen? 
Everytime

Additional Information:
Comment 1 Marek Safar 2012-02-20 11:36:40 UTC
Decimal constants cannot be used as an attribute arguments.

If your code compiles with csc than the problem is somewhere else.
Comment 2 Alexey Pelykh 2012-02-20 11:40:40 UTC
Can you please confirm that this log is produced by usage of Microsoft compiler and not Mono compiler? Since I suppose that my explanation was not super exact


C:\Program Files (x86)\Mono-2.10.8\bin\dmcs.bat /noconfig "/out:D:\TOM\tom\entities\Currencies\bin\Release\Currencies.dll"
 "/r:D:\TOM\tom\third-party\nhibernate\NHibernate.Validator.dll"
 "/r:C:\Program Files (x86)\Mono-2.10.8\lib\mono\4.0\System.dll"
 "/r:D:\TOM\tom\third-party\nhibernate\Iesi.Collections.dll"
 "/r:D:\TOM\tom\third-party\nhibernate\NHibernate.dll"
 "/r:D:\TOM\tom\third-party\nhibernate\NHibernate.Mapping.Attributes.dll"
 "/r:D:\TOM\tom\entities\EntitiesCore\bin\Release\EntitiesCore.dll"
 "/r:D:\TOM\tom\nhibernate-extensions\nhValidation\bin\Release\nhValidation.dll"
 "/r:C:\Program Files (x86)\Mono-2.10.8\lib\mono\4.0\System.Core.dll"
 /nologo
 /warn:4
 /optimize-
 /codepage:utf8
 /t:library
 "D:\TOM\tom\entities\Currencies\AssemblyInfo.cs"
 "D:\TOM\tom\entities\Currencies\CurrencyEntity.cs"
 "D:\TOM\tom\entities\Currencies\ExchangeRateEntity.cs"
 

Compilation failed: 4 error(s), 0 warnings



D:\TOM\tom\entities\Currencies\ExchangeRateEntity.cs(108,26): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression

D:\TOM\tom\entities\Currencies\ExchangeRateEntity.cs(118,22): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression

D:\TOM\tom\entities\Currencies\ExchangeRateEntity.cs(128,22): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression

D:\TOM\tom\entities\Currencies\ExchangeRateEntity.cs(138,22): error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression
Comment 3 Alexey Pelykh 2012-02-20 11:42:48 UTC
But same code is compiled my Microsoft compiler normally. What indicates to that this is bug in Mono compiler or [un]documented feature of Microsoft compiler.
Comment 4 Marek Safar 2012-02-20 11:46:08 UTC
It's possibly bug in Mono compiler but I could not reproduce it using details you provided.

You didn't provide reproducible test, so I had to try recreate it myself

using System;

public class entity
{
	[DecimalMin (0m)]
	public virtual decimal CashlessAdditionalPercentToOfficialRate { get; set; }

	public static void Main ()
	{
	}
}

class DecimalMinAttribute : Attribute
{
	public DecimalMinAttribute (decimal value)
	{
	}
}

This code fails with Mono and .NET compilers
Comment 5 Alexey Pelykh 2012-02-20 11:57:31 UTC
Sorry for that, but indeed sample gives errors on both sides. Again, I'm very sorry. At least I can not figure out why it compiled before
Comment 6 Alexey Pelykh 2012-02-20 12:00:29 UTC
http://msdn.microsoft.com/en-us/library/09ze6t76(v=vs.90).aspx me dumb