I am unable to use the await keyword in my MvvmCross Windows Phone 7.1 project while using the Microsoft.Bcl "Microsoft BCL Portability Pack".
I have posted the code for the sample project that I describe below on GitHub and the await error occurs on this line.
When I try to build the third "Core" Windows Portable Class Library (PCL) that contains the FirstViewModel, I get the errors of:
Type System.Threading.Tasks.Task<string> not awaitable under VS red squiggles, and
Cannot await 'System.Threading.Tasks.Task<string>' when building.
There are four projects in the solution:
A Windows Portable Class Library (PCL) with an interface in it that references that "Task" object provided by the BCL.
A Windows Phone Class Library targeting OS 7.1 that implements the interface above and also uses "Task" from the BCL.
Another Windows Portable Class Library (PCL) that provides the "Core" functionality of the app, including the ViewModel.
The Windows Phone 7.1/"7.5" application that tries to reference and consume the DLL's above.
The first two projects containing the interface and the implementation of the interface compile without any errors. But the 3rd "Core" PCL fails to build with the errors shown above.
More Details If You Want Them:
I tried this App.config "fix" as described here in the "known BCL issues": http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx .But that did not resolve the error when I added App.config to just the "Core" project, nor when I tried to add the same App.config to every project. It is possible that I am not using the right version in the element or I just did the App.config stuff incorrectly.
Every project in the solution that is set to target a PCL are set to "Profile104" in Visual Studio.
Those DLL's are located in:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\
This PCL profile is shown as targeting these platforms in the Visual Studio project properties: .NET for Windows Store apps, .NET 4.5, Silverlight 4+, and Windows 7.5+
Every project in the solution also has reference to the Microsoft.Bcl "Microsoft BCL Portability Pack" via NuGet.
All four projects are using MvvmCross (Mvx).
None of the projects in this sample are trying to target anything related to the Xamarin Droid/iOS stack yet. It is all Windows and is still failing on the await keyword.
The PCL with the interface in it and the Windows Phone Class Library both use the Mvx CrossCore NuGet Package and are setup to be consumed as "Mvx Plugins".
The "Core" PCL is using the full MvvmCross NuGet package and contains the FirstViewModel where the await error is occurring.
The Windows Phone App project references the full MvvmCross as well, with the Windows Phone-specific Mvx files pulled in to it.
as mentioned, see the failing sample code on GitHub.
You need to add the Microsoft.Bcl.Async
NuGet package.
These packages were previously unavailable on non-Microsoft platforms, but as part of the Xamarin collaboration Microsoft relicensed them to be usable under all platforms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With