简体   繁体   English

为什么我在使用Microsoft.Bcl时不能在Windows Phone 7.1 MvvmCross项目中使用await关键字 - 无法等待'System.Threading.Tasks.Task?

[英]Why can't I use await keyword in my Windows Phone 7.1 MvvmCross project while using the Microsoft.Bcl - cannot await 'System.Threading.Tasks.Task?

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". 在使用Microsoft.Bcl“Microsoft BCL Portability Pack”时,我无法在MvvmCross Windows Phone 7.1项目中使用await关键字。

I have posted the code for the sample project that I describe below on GitHub and the await error occurs on this line . 我已经在GitHub上发布了我在下面描述的示例项目的代码, 并且此行发生了await错误

When I try to build the third "Core" Windows Portable Class Library (PCL) that contains the FirstViewModel, I get the errors of: 当我尝试构建包含FirstViewModel的第三个“核心”Windows可移植类库(PCL)时,我得到以下错误:

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: 解决方案中有四个项目:

  1. A Windows Portable Class Library (PCL) with an interface in it that references that "Task" object provided by the BCL. Windows可移植类库(PCL),其中包含一个接口,用于引用BCL提供的“任务”对象。

  2. A Windows Phone Class Library targeting OS 7.1 that implements the interface above and also uses "Task" from the BCL. 一个针对OS 7.1的Windows Phone类库,它实现了上面的接口,并且还使用了BCL中的“任务”。

  3. Another Windows Portable Class Library (PCL) that provides the "Core" functionality of the app, including the ViewModel. 另一个Windows可移植类库(PCL),提供应用程序的“核心”功能,包括ViewModel。

  4. The Windows Phone 7.1/"7.5" application that tries to reference and consume the DLL's above. 试图引用和使用上述DLL的Windows Phone 7.1 /“7.5”应用程序。

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. 但第三个“核心”PCL无法使用上面显示的错误构建。

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. 我尝试了这个App.config“修复”,如“已知的BCL问题”中所述: http//blogs.msdn.com/b/bclteam/p/asynctargetingpackkb.aspx 。但是当我添加时没有解决错误App.config只是“核心”项目,当我尝试将相同的App.config添加到每个项目时。 It is possible that I am not using the right version in the element or I just did the App.config stuff incorrectly. 有可能我没有在元素中使用正确的版本或我只是错误地做了App.config的东西。

  • Every project in the solution that is set to target a PCL are set to "Profile104" in Visual Studio. 解决方案中设置为以PCL为目标的每个项目在Visual Studio中都设置为“Profile104”。

Those DLL's are located in: 那些DLL位于:

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+ 此PCL配置文件显示为在Visual Studio项目属性中定位这些平台:.NET for Windows Store应用程序,.NET 4.5,Silverlight 4+和Windows 7.5+

  • Every project in the solution also has reference to the Microsoft.Bcl "Microsoft BCL Portability Pack" via NuGet. 解决方案中的每个项目也都通过NuGet引用了Microsoft.Bcl“Microsoft BCL Portability Pack”。

  • All four projects are using MvvmCross (Mvx). 所有四个项目都使用MvvmCross(Mvx)。

  • None of the projects in this sample are trying to target anything related to the Xamarin Droid/iOS stack yet. 此示例中的所有项目都没有尝试定位与Xamarin Droid / iOS堆栈相关的任何内容。 It is all Windows and is still failing on the await keyword. 它是所有Windows,并且仍然在await关键字上失败。

  • 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". 带有接口的PCL和Windows Phone类库都使用Mvx CrossCore NuGet包,并设置为“Mvx插件”。

  • The "Core" PCL is using the full MvvmCross NuGet package and contains the FirstViewModel where the await error is occurring. “Core”PCL使用完整的MvvmCross NuGet包,并包含发生等待错误的FirstViewModel。

  • The Windows Phone App project references the full MvvmCross as well, with the Windows Phone-specific Mvx files pulled in to it. Windows Phone App项目也引用了完整的MvvmCross,并将Windows Phone特定的Mvx文件引入其中。

  • as mentioned, see the failing sample code on GitHub . 如上所述, 请参阅GitHub上失败的示例代码

You need to add the Microsoft.Bcl.Async NuGet package. 您需要添加Microsoft.Bcl.Async NuGet包。

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. 这些软件包之前在非Microsoft平台上不可用,但作为Xamarin协作的一部分,Microsoft 重新授权它们可在所有平台下使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 方法错误“无法从等待和异步属性中等待” System.Threading.Tasks.Task” - Method Error 'Cannot await 'System.Threading.Tasks.Task' from await and async properties PostSharp:在Windows Phone 7项目中与Microsoft.Bcl一起使用时,BindingException - PostSharp: BindingException when using with Microsoft.Bcl in Windows Phone 7 project 无法将类型“Microsoft.AspNetCore.Mvc.NotFoundResult”隐式转换为“System.Threading.Tasks.Task” - Cannot implicitly convert type 'Microsoft.AspNetCore.Mvc.NotFoundResult' to 'System.Threading.Tasks.Task' 无法将类型&#39;void&#39;隐式转换为&#39;System.Threading.Tasks.Task&#39; - Cannot implicitly convert type 'void' to 'System.Threading.Tasks.Task' 无法隐式转换类型&#39;System.Threading.Tasks.Task - Cannot implicitly convert type 'System.Threading.Tasks.Task 运行System.Threading.Tasks.Task时出现异常 - Exception while running System.Threading.Tasks.Task 无法将类型“System.Threading.Tasks.Task”隐式转换为“Windows.Foundation.IAsyncAction”。 存在显式转换 - Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'Windows.Foundation.IAsyncAction'. An explicit conversion exists “System.Func`1[System.Threading.Tasks.Task]”类型的表达式不能用于返回类型“System.Threading.Tasks.Task” - Expression of type 'System.Func`1[System.Threading.Tasks.Task]' cannot be used for return type 'System.Threading.Tasks.Task' 无法将 System.Threading.Tasks.Task... 转换为 System.Threading.Tasks.Task... 尽管看似相同的类型 - Cannot convert System.Threading.Tasks.Task… to System.Threading.Tasks.Task… despite seemingly being same type 类型&#39;System.Threading.Tasks.Task&#39;无法序列化 - Type 'System.Threading.Tasks.Task' cannot be serialized
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM