1

This seems like it should be easy, but searching on the web has not turned up anything. I want to take advantage of C#'s async and await, but I have C# version 4.0.30319 (which I got from Console.Write(typeof(string).Assembly.ImageRuntimeVersion);).

I just upgraded from VS12 to VS13, and I am using .NET 4.5. I thought my C# version would upgrade as well, but it hasn't (async and await still give errors).

Any ideas?

Steven Jeffries
  • 3,522
  • 2
  • 20
  • 35
  • 2
    Provide example of one of the code issues as an example. – ΩmegaMan May 09 '14 at 20:23
  • @Servy why dont you post this as an answer..I will upvote – apomene May 09 '14 at 20:25
  • @apomene I'm tempted to, and yet it doesn't explain why his code isn't compiling... – Servy May 09 '14 at 20:25
  • possible duplicate of [What are the correct version numbers for C#?](http://stackoverflow.com/questions/247621/what-are-the-correct-version-numbers-for-c) – Black Frog May 09 '14 at 20:28
  • He also hasn't posted a code example which might show what the problem is. – Otis May 09 '14 at 20:29
  • The only thing I can think of at this point is the Language Version is not set to default on the project. Open up your Project's properties, click the "Build", then "Advanced", and see what "Language Version" is set to. – vcsjones May 09 '14 at 20:29
  • @StevenJeffries can you post code of async/await code you are attempting to use and what error it is giving? – arserbin3 May 09 '14 at 20:29
  • @Black Frog: semi-duplicate, the OP is more interested in why some code won't run then in what C# version matches to what framework version. – Otis May 09 '14 at 20:30
  • @Otis, since the OP hasn't posted any code, this question is a duplicate because the title say how do I upgrade to c# 5. – Black Frog May 09 '14 at 20:49

2 Answers2

10

Versioning is complex...

  • There's the version of the .NET runtime, which for you is version 4.5.
  • Then there's the version of the C# language being used, which is at least 5.0 if you're using version if you're using VS 2012 or 2013 (You are using C# 5.0 when using C# in those versions of Visual Studio, even if targeting an earlier .NET runtime , which was introduced with version 4.5 of the .NET framework.
  • Then there's the Common Language Runtime (CRL), which for you is 4.0.30319, as returned by Assembly.ImageRuntimeVersion
Servy
  • 202,030
  • 26
  • 332
  • 449
2

What you're checking is not the version of C# - 4.0.30319 is the version of Common Language Runtime you are using (that's what Assembly.ImageRuntimeVersion means).

If you're using .NET 4.5 on Visual Studio 2013, you're already using C# 5.0.

Sunius
  • 2,789
  • 18
  • 30
  • Actually, it's the version of the *C# compiler*, not the version of the .NET runtime. He's using the *compiler* version 4.0.X to compile C# 5.0 code against the .NET 4.5.X runtime. – Servy May 09 '14 at 20:27