eidylon
eidylon

Reputation: 7238

C# Default Parameters being yelled about

I have a web app I have been tasked with trying to debug and fix. Not my code. The app is targeting the 4.0 Framework, which as near as I can tell, is C# version 4.0 as well.

The website will not compile, and is giving the following error: Default parameter specifiers are not permitted.

It complains in two spots, here is one of them:

private static void setDateCell(string cellXY, object value, string format = "MM/dd/yyyy") {

The other spot is a similar function declaration but for numbers and with a different default format.

As far as I can tell from here, v4.0 of C# was when default parameters were introduced. I've double checked the web site property pages to make sure it is targeting Framework 4.0. So I'm not sure why it is complaining about having optional parameters.

I've tried running aspnet_regiis -i; no joy.

Any ideas?

We were using VS2010 Express. We're currently installing VS2015 Express... to see if maybe it is an issue with 2010.

Upvotes: 0

Views: 190

Answers (2)

eidylon
eidylon

Reputation: 7238

Thanks to Serge, who's answer turned me on to the problem. Visual Studio 2010 does not support compiling with that attribute. We installed VS2015 on the machine, and edited it there, and then we were able to target a higher Framework version, and continue on our way.

Upvotes: 0

Serge Wautier
Serge Wautier

Reputation: 21878

Check the targetFramework attribute of the <compilation> node of your Web.config. Maybe it's stuck to something lower than 4.0 for some reason. Another way to check/fix this is to toggle your project to 3.5, then to 4.0 again.

Upvotes: 2

Related Questions