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?

1
  • Is the function being called from inside the .aspx file, or from inside the codebehind for that file? Commented Jun 16, 2011 at 16:34

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

2 Comments

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.