Why can't I use the wait keyword in my Windows Phone 7.1 MvvmCross project when using Microsoft.Bcl - can't wait for System.Threading.Tasks.Task?

I cannot use the wait keyword in my MvvmCross project for Windows Phone 7.1 when using Microsoft.Bcl "Microsoft BCL Portability Pack".

I have posted the code for an example project, which I will describe below on GitHub, and there is a wait error on this line .

When I try to create a third "Core" Windows Portable Class Library (PCL) that contains the FirstViewModel, I get errors:

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) library with an interface in it that references the Task object provided by BCL.

  • The Windows Phone-based class library that focuses on OS 7.1, which implements the interface above, and also uses the "Task" from BCL.

  • Another Windows Portable Class Library (PCL) that provides the "Basic" features of the application, including ViewModel.

  • Windows Phone 7.1 / "7.5" application that tries to link and use the DLL above.

The first two projects containing the interface and the implementation of the interface are compiled without any errors. But the third β€œCore” PCL cannot build with the errors shown above.

More if you want them:

  • I tried the β€œfix” App.config as described here in the β€œknown BCL issues”: http://blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx . But this did not resolve the error when I added App.config only to the "Core" project, and when I tried to add the same App.config for each project. It is possible that I am not using the correct version in the element, or I just used the App.config file incorrectly.

  • Each project in a solution configured on the target PCL is installed in "Profile104" in Visual Studio.

These dlls are located in:

 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\ 
  • This PCL profile is displayed as targeting these platforms in the Visual Studio project properties: .NET for Windows Store, .NET 4.5, Silverlight 4+, and Windows 7.5 + applications

  • In each project, the solution also contains a link to Microsoft.Bcl "Microsoft BCL Portability Package" through NuGet.

  • All four projects use MvvmCross (Mvx).

  • None of the projects in this example try to configure anything related to Xamarin Droid / iOS. This is all Windows and still does not work on the wait keyword.

  • PCLs with an interface in it and a Windows Phone class library use the Mvx CrossCore NuGet package and are configured to be used as Mvx plugins.

  • The "Core" PCL uses the full NvGet MvvmCross package and contains the FirstViewModel in which the wait error occurs.

  • The Windows Phone App project refers to the full MvvmCross, as well as the Mvx files associated with Windows Phone.

  • as mentioned, see the unsuccessful GitHub code example .

+4
source share
1 answer

You need to add the Microsoft.Bcl.Async NuGet package.

These packages were previously not available on platforms other than Microsoft, but as part of the Xamarin collaboration, Microsoft relicensed them can be used on all platforms.

+12
source

Source: https://habr.com/ru/post/1498291/


All Articles