When running a build via TeamCity, I started to get the following exception:
CSC error CS0182: An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
The same code built fine in Visual Studio 2012, and nothing had changed on the build server so clearly something in the most recent commits was triggering a difference in behaviour between the two environments.
It turns out that there’s a compiler bug in C# 4.0 (which our TeamCity server was using) involving null default parameters for attributes (an instance of which had been introduced in a recent commit) e.g.:
public SomeAttribute(SomeType someParameter = null)
When an attribute contains a parameter in its constructor that defaults to null, the compiler incorrectly treats this as being a typeless null literal rather than a constant expression and throws the exception in question.
The proper fix for this is to upgrade the compiler on the build server. However, as that isn’t always immediately practical, as a workaround you can simply cast the null parameter to the type in question e.g.:
public SomeAttribute(SomeType someParameter = (SomeType)null)
Eric Lippert provides more information about this particular bug in this StackOverflow answer.
2 Comments
Totally saved my bacon in < 5 minutes with this (in this case though, build box was using MS Build / TFS, but still using an older version of the compiler and therefore, failing there and not locally).
Nice Post
32 Trackbacks
download blog
C# compiler error CS0182 when building via TeamCity
anina tools & electricals
C# compiler error CS0182 when building via TeamCity
Discover More
C# compiler error CS0182 when building via TeamCity
http://www.33338888.cc/comment/html/index.php?page=1&id=28564
C# compiler error CS0182 when building via TeamCity
niftalumni.in
C# compiler error CS0182 when building via TeamCity
beta.finegardening.com
C# compiler error CS0182 when building via TeamCity
http://phpweb.xa95.net/comment/html/index.php?page=1&id=6967
C# compiler error CS0182 when building via TeamCity
Electrical jobs abroad maintenance
C# compiler error CS0182 when building via TeamCity
cheap hotels In London Piccadilly Circus
C# compiler error CS0182 when building via TeamCity
cheap hotels in myrtle beach sc near family kingdom
C# compiler error CS0182 when building via TeamCity
http://www.promotioncodes.org.uk
C# compiler error CS0182 when building via TeamCity
aeropostale online coupon Codes may 2011
C# compiler error CS0182 when building via TeamCity
shore-215.blogspot.ae
C# compiler error CS0182 when building via TeamCity
online shopping department stores australia
C# compiler error CS0182 when building via TeamCity
ecommerce online store
C# compiler error CS0182 when building via TeamCity
senator john lewis quotes
C# compiler error CS0182 when building via TeamCity
budget hotels in rome city centre italy
C# compiler error CS0182 when building via TeamCity
outdoor chair hire melbourne
C# compiler error CS0182 when building via TeamCity
http://flourishorfail.com/2015/08/Ensure-residence-security-set-up-wylex-consumer-unit-heat-alarm-and-smoke-alarm
C# compiler error CS0182 when building via TeamCity
http://www.5062studio.net
C# compiler error CS0182 when building via TeamCity
promotion code shoes for little feet
C# compiler error CS0182 when building via TeamCity
theunion.net
C# compiler error CS0182 when building via TeamCity
kohlberg kravis roberts co ltd
C# compiler error CS0182 when building via TeamCity
furniture Stores online usa
C# compiler error CS0182 when building via TeamCity
Discount Furniture In San Diego
C# compiler error CS0182 when building via TeamCity
Marc jacobs amy watch John lewis
C# compiler error CS0182 when building via TeamCity
momshub.co
C# compiler error CS0182 when building via TeamCity
learn auto mechanics
C# compiler error CS0182 when building via TeamCity
Bb-Cochem.com
C# compiler error CS0182 when building via TeamCity
Dent Masters
C# compiler error CS0182 when building via TeamCity
website
C# compiler error CS0182 when building via TeamCity
barn with metal roof
C# compiler error CS0182 when building via TeamCity