Paul
Paul

Reputation: 79

async await task.run - not found

VS2012, C#, XAML, Windows Phone7 app (just migrated from Win7/VS2010).

I've just migrated my WP7 app to Win8/VS2012. (I mention this in case the issue below might indicate that I may be pointing to an incorrect DLL.) The app migrated just fine. I'm in the process of adding some additional async processing that I prototyped in VS2012 and am getting flagged by VS that the following is incorrect:

var _Token = await Task.Run(() => (Token)_Serializer.ReadObject(_Response.GetResponseStream()));

VS is saying that "System.Threading.Tasks.Task does not contain a definition for 'Run'." The Reference for System.Threading.Tasks in my WP7 app points to this location: \packages\Microsoft.Bcl.1.0.16-rc\lib\sl4-windowsphone71\System.Threading.Tasks.dll

I added the Microsoft.Bcl.1.0.16-rc via NuGet to complete the migration to VS2012. Was this incorrect? Previously I was using AsyncCtpLibrary_Phone and was advised that obtaining Microsoft.Bcl.Async would resolve the build errors such as:

The type 'System.Threading.Tasks.Task' exists in both AsyncCtpLibrary_Phone.dll' >and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0\mscorlib.dll. After adding the Microsoft.Bcl.Async the wp7 app built correctly and ran.

It was only after attempting to drop NEW async code I'd prototyped in VS2012 that the Task.Run issue arose.

The app.config contains this entry:

<dependentAssembly bcl:name="System.Threading.Tasks">
    <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.5.11.0" newVersion="1.5.11.0" />
</dependentAssembly>

Is there an additional package I need to install?

Thanks in advance, Paul

Upvotes: 3

Views: 3883

Answers (4)

Stephen Cleary
Stephen Cleary

Reputation: 456587

In Microsoft.Bcl.Async, just like in the Async CTP, the Run method is on the TaskEx type instead of Task.

Upvotes: 16

Arno Venter
Arno Venter

Reputation: 51

The Microsoft.Bcl.Async dll from NuGet is fine.

The problem is that the syntax is just different. Don't use:

await Task.Run(() => ...);

You should just be using:

await Task.Factory.StartNew(() => ...);

Upvotes: -1

James Manning
James Manning

Reputation: 13579

I believe the problem is the references you still have to the older async CTP assemblies which include the same types (as per compiler error). Those were the right references when using VS2010, but need to be removed now AFAICT.

IMHO, I would do these steps:

  • remove the Microsoft.Bcl and Microsoft.Bcl.Async (via NuGet, however you added them)
  • remove the Async CTP libraries (AsyncCtpLibrary*.dll)
  • ensure compiling fails to find the types
  • add Microsoft.Bcl.Async via NuGet
  • ensure compiling works

I don't understand WP7.1 vs 7.5, but since the compiler error mentioned the WP8 ref, I think you're ok.

Upvotes: 0

Igor Ralic
Igor Ralic

Reputation: 15006

The last time I checked, the Async CTP did not work in Visual Studio 2012, as it is an extension of Visual Studio 2010. I am afraid you'll have to stick with VS 2010 as long as you're targeting Windows Phone 7.

Possible more useful information here.

Upvotes: 0

Related Questions