Bug 13140 - MediaPlayer.PrepareAsync "Cannot await 'void' expression"
Summary: MediaPlayer.PrepareAsync "Cannot await 'void' expression"
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.7.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2013-07-09 20:29 UTC by Timothy Risi
Modified: 2013-07-09 22:57 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Timothy Risi 2013-07-09 20:29:56 UTC
Receive the title error when building on the line:

    await player.PrepareAsync ();

Code is in an async method.  In this case, turning the strtPlayer () method in the Example_WorkingWithAudio sample to async and changing 'player.Prepare ()' to 'await player.PrepareAsync ()'.  The project builds successfully without the await keyword.

Error:
/Users/Tim/Projects/Xamarin/monodroid-samples/Example_WorkingWithAudio/Example_WorkingWithAudio/PlayAudio.cs(18,18): Error CS4001: Cannot await `void' expression (CS4001) (Example_WorkingWithAudio)

7/9/13
Xamarin Studio
Xamarin.Android 4.7.11
OS X 10.8.4
Comment 1 Jonathan Pryor 2013-07-09 22:57:18 UTC
Just because a method has an "Async" suffix doesn't mean that it follows the C#5 async method pattern, especially when nothing prevents Java from having "Async"-suffixed methods.

Case in point, MediaPlayer.prepareAsync() is a Java method, and it returns `void`:

http://developer.android.com/reference/android/media/MediaPlayer.html#prepareAsync()

Our "asyncification" effort adds "Async overloads" for non-async methods. It does NOT change Java-defined methods which happen to match the C#5 async naming convention so that they conform to the C#5 async pattern.