Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Async CTP with Portable Class Library

I am trying to rewrite a project into a Portable Class Library. But the problem is that it is using Async CTP, and I can't compile it as a library for WP and Windows Store App. If I don't include reference AsyncCtpLibrary.dll, compiler says that

The type or namespace name 'Tasks' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)

If i include it, compiler still says the same errors and adds a warning:

The primary reference "AsyncCtpLibrary" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "AsyncCtpLibrary" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

How should I bear with that?

like image 640
passick Avatar asked Sep 26 '12 08:09

passick


2 Answers

You can only currently use async/await in portable when targeting .NET 4.5 and Window Store apps. Outside of portable, you can use the Async Targeting Pack for .NET 4.0 and Silverlight 5.

In saying that though, we are working on an updated async targeting pack that adds support for async/await in portable when targeting Phone 7.5, Silverlight 5 and .NET 4.0, see: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2691068-support-async-in-portable-class-libraries. You will see this early October.

Update: We just release a beta of this: http://blogs.msdn.com/b/bclteam/archive/2012/10/22/using-async-await-without-net-framework-4-5.aspx.

like image 150
David Kean Avatar answered Sep 28 '22 05:09

David Kean


Simple answer - AsyncCTP is not working in Visual Studio 2012 and cannot be used in any project. For .NET 4.0 and Silverlight 5 you can install Async Targeting Pack from NuGet that works in a similar fashion.
Async/await is in Portable Class Library supported only when targeting WinRT, .NET4.5 or Windows Phone 8 and even then the use is pretty limited. I can't go into more details here, because the Windows Phone 8 SDK is still under NDA.
For WP7.5 and VS2012 there is currently no way how to use async/await, but updated Async Targeting Pack for this platform should be available sometime.
Note also that AsyncCTP and Async Targeting Pack can't be used in Portable Class Libraries and it's unlikely it will change in the future. The result is in VS2010 you cannot use async/await in Portable Class Libraries.

like image 31
Martin Suchan Avatar answered Sep 28 '22 05:09

Martin Suchan