5

Scenario:

I have VS 2010 (C# 4 compiler) targeting 3.5 on my client machine.

I am developing ASP.NET applications. I use optional parameters (C# 4 supported) in a class file and compile the code everything appears to work fine.

Later on an issue that is discovered at Runtime where an old (classic I believe) ASPX is using the function. No function accepts only x arguments where x is one less than the optional parameter is the runtime error.

Does this mean normal classes and such use the C# compiler of the client, while the views (aspx) and such use the compiler on the server - thus causing issues if C# 4 is used in view/form files?

Joshua Enfield
  • 17,642
  • 10
  • 51
  • 98

1 Answers1

3

I believe this has to do with the fact that aspx pages are (re?)compiled on first load by IIS rather than being compiled in Visual Studio. This allows them to be updated on the fly without recompiling, however since they're compiled by IIS it brings the complications you're seeing.

I'm not aware of a way to have IIS use the C#4 compiler but compile to .NET 3.5 so it seems like your only options are:

  1. Update to .NET 4
  2. Don't use optional parameters
  3. Don't call code that uses optional parameters in your .aspx files. I'm guessing if you move the calls to the codebehind file it should work fine, but I haven't tried it.
Davy8
  • 30,868
  • 25
  • 115
  • 173
  • http://stackoverflow.com/questions/1210679/can-you-use-optional-parameters-in-code-targeting-net-3-5 – Adam Tuliper Jun 16 '11 at 17:31
  • @Adam I'm well aware that you are able to use optional parameters while targeting .NET 3.5, as long as it is using the C# 4.0 compiler. The point I was trying to make though is that while you can do that in Visual Studio, I'm not aware of a way to have IIS use the C#4 compiler while targeting .NET 3.5 when it recompiles .aspx pages on the fly. – Davy8 Jun 16 '11 at 17:36