This project has moved and is read-only. For the latest updates, please go here.

3.0.1 'await' not working

Jan 22, 2014 at 3:44 PM
Apologies if I'm missing something and appreciation for the help...

I'm attempting to get the sample code running with the latest beta of 3.0.1 and am running into a compilation roadblock. Visual Studio is underlining the 'await' keyword prior to the LINQ query and stating that "The 'await' operator can only be used with an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'."

I've tried this with VS2012 and VS2013 (w/ 4.5.1). Same error message in both.

Here is the code example I'm trying:
var auth = new SingleUserAuthorizer
                CredentialStore = new SingleUserInMemoryCredentialStore
                    ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"],
                    AccessToken = ConfigurationManager.AppSettings["accessToken"],
                    AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]

            var twitterCtx = new TwitterContext(auth);

            var searchResponse =
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == "\"LINQ to Twitter\""
                 select search)

            if (searchResponse != null && searchResponse.Statuses != null)
                searchResponse.Statuses.ForEach(tweet =>
                        "User: {0}, Tweet: {1}",
Jan 22, 2014 at 3:54 PM
UPDATE: Please ignore until I RTFM on the async/await pattern. Haven't used it before ... and the fact that I was attempting to just "paste the code in" to a console app without any consideration for the fact that it is an async call is boneheaded. Apologies for the bother. :P

Jan 22, 2014 at 4:44 PM
Without wishing to hijack this thread, but I've bumped into the same "The 'await' operator can only be used with an async method. Consider marking this method with the 'async' modifier" message, using the same code but with the ToListAsync() method instead of SingleOrDefaultAsync()." on the same example code. I downloaded the source code example for Windows Phone from codeplex but that seems to refer to the old version 2.1.11. Is there some example code for the 3.0.1 beta for Windows Phone?
Jan 22, 2014 at 6:26 PM

No problem. By just asking the question, you've probably helped a lot of people who are in the same boat and will be searching the forum for an answer. :)

Jan 22, 2014 at 6:28 PM

All of the LINQ to Twitter v3.0 demos have a Linq2TwitterDemo_ prefix and there's one called Linq2TwitterDemo_WindowsPhone.