Derik Whittaker



Async/Await & ‘Does not contain a definition for GetAwaiter’ error

I have been working on a side project and today I ran into a really odd error which had me stumped for a few minutes.  I would run my code and the following error would be thrown.

{"KioskUpdateManifest' does not contain a definition for 'GetAwaiter'"}

Take a look at the code below

public async Task<KioskCheckinManifest> Checkin(dynamic manifest)

        if (manifest == null) { throw new ArgumentNullException("manifest", "Provided manifest was null"); }
        if (manifest.Context == null) { throw new ArgumentNullException("manifest", "Provided context was null"); }

        if (manifest.Context != null)
            var asJson = manifest.Context.ToString();
            var asManifest = JsonConvert.DeserializeObject<KioskCheckinManifest>(asJson);
            var checkinResult = await _kiosksService.Checkin(asManifest);
            return checkinResult;
    catch (Exception e)
        Logger.LogException("KioskHub.Checking", e);

    return new KioskCheckinManifest();

At first when trying to debug this code I thought something was wrong w/ the way my object was being deserialized, but no that was correct.  Then I thought that maybe my KiosksService.Checkin call was producing the error, but again no it was not.  I took a look at this for a bit longer and I realized that the GetAwaiter was part of the async/await stuff.  Realizing I was dealing w/ async issues I knew the following line of code had to be the culprit, but why.

var checkinResult = await _kiosksService.Checkin(asManifest);

To try to resolve the issue I went to the implementation of my .Checkin and I quickly realized that I was trying to await a method which was not awaitable.  As soon as I removed the await keyword from my call everything worked as expected.

Now it makes 100% sense to get an error when trying to await a non-awaitable method, but my real issue is why does the compiler not give me a warning, or better yet an error?

The moral of the story is this.  If you get this error make sure you are not awaiting a non-awaitable method.

Till next time,

Posted 12-29-2013 6:15 AM by Derik Whittaker
Filed under: ,



Jason Haley wrote Interesting Finds: December 29, 2013
on 12-29-2013 8:04 AM

Interesting Finds: December 29, 2013

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)