Out of curiosity, I'm trying to get some simple async
/await
code to compile under .NET 3.5 Client Profile:
async void AwaitFoo()
{
await new Foo();
}
class Foo
{
public IFooAwaiter GetAwaiter() { … }
}
interface IFooAwaiter : System.Runtime.CompilerServices.INotifyCompletion
{
bool IsCompleted { get; }
void GetResult();
}
I'm perfectly aware that .NET 3.5 does not support this language feature, as expressed by this compilation error:
Cannot find all types required by the
async
modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?
I am also aware of the NuGet package Microsoft.Bcl.Async
, which does not have support for .NET 3.5.
Question: What is the minimum set of types & type members required for async
code to compile? Is this minimal set officially documented; and if so, where? (Note that I'm only interested in successful compilation, not execution.)
What I've got so far:
I've been trying to find this minimum set of types by experiment, which appears to be possible since the compiler reports required, but missing types one by one:
Predefined type
System.Runtime.CompilerServices.IAsyncStateMachine
is not defined or imported.
Defining the reported type according to MSDN reference pages then leads to the next missing type being reported. I have so far:
System.Runtime.CompilerServices.IAsyncStateMachine
System.Runtime.CompilerServices.INotifyCompletion
(required by the example code above)System.Threading.Tasks.CancellationToken
(required byTask
)System.Threading.Tasks.TaskCreationOptions
(required byTask
)System.Threading.Tasks.Task
At this point I stopped, since Task
has lots of members, but the compiler does not report exactly which members it requires; it just reports the type as a whole. I might therefore reproduce much more of the type definition than what is actually needed.