Search code examples
c#async-awaitlinqpad

Unable to use async/await in LINQPad - "Invalid token {after async} in .."


I wanted to try the "new" async/await (yeah, I'm late to the party) so I fired up LINQPad 4.5.1 which is currently the latest non-beta. After switching to "C# Program" and input the following code, sans comment;

// "Invalid token 'void' in class, struct, or interface member declaration"
// - But compiles with `async` removed
async void foo () {
}

void Main()
{
    foo();
}

But it .. "doesn't work" as indicated.

This error seems to indicate that LINQPad is using C#4 and not C#5 although the website does say "LINQPad supports everything in C# 5.0 and Framework 4.x" and others don't seem to have this problem.

What causes this error, and how can it be resolved?


Solution

  • Well, that was .. silly of me. The current machine had .NET 4 - not 4.5 - installed.

    After installing .NET 4.5 "it works".