Client
iGame Channel = new ChannelFactory ( new BasicHttpBinding ( BasicHttpSecurityMode . None ) , new EndpointAddress ( new Uri ( \"http://loc
GetAwaiter()
, that is used by await
, is implemented as an extension method in the Async CTP. I'm not sure what exactly are you using (you mention both the Async CTP and VS 2012 RC in your question), but it's possible the Async targeting pack uses the same technique.
The problem then is that extension methods don't work with dynamic
. What you can do is to explicitly specify that you're working with a Task
, which means the extension method will work, and then switch back to dynamic
:
private async void MyButtonClick(object sender, RoutedEventArgs e)
{
dynamic request = new SerializableDynamicObject();
request.Operation = "test";
Task<SerializableDynamicObject> task = Client(request);
dynamic result = await task;
// use result here
}
Or, since the Client()
method is actually not dynamic, you could call it with SerializableDynamicObject
, not dynamic
, and so limit using dynamic
as much as possible:
private async void MyButtonClick(object sender, RoutedEventArgs e)
{
var request = new SerializableDynamicObject();
dynamic dynamicRequest = request;
dynamicRequest.Operation = "test";
var task = Client(request);
dynamic result = await task;
// use result here
}
public async Task<model> GetSomething(int id)
{
return await context.model.FindAsync(id);
}
You could still use framework 4.0 but you have to include getawaiter
for the classes:
MethodName(parameters).ConfigureAwait(false).GetAwaiter().GetResult();
In case it helps anyone, the error message:
'does not contain a definition for 'GetAwaiter'' etc.
also occurs if the await is incorrectly placed before the variable like this:
instead of:
RtfAsTextLines = await OpenNoUserInterface(FilePath);
Just experienced this in a method that executes a linq query.
public async Task<Foo> GetSomething()
{
return await (from foo in Foos
select foo).FirstOrDefault();
}
Needed to use .FirstOrDefaultAsync()
instead. N00b mistake.
The Problem Occur Because the application I was using and the dll i added to my application both have different Versions.
Add this Package- Install-Package Microsoft.Bcl.Async -Version 1.0.168
ADDING THIS PACKAGE async Code becomes Compatible in version 4.0 as well, because Async only work on applications whose Versions are more than or equal to 4.5