Cannot be used in Portable Class Library for Win 8 and Win Phone 8

I am trying to create a portable class library in Visual Studio 2012 that will be used for the Windows 8 Store app and the Windows Phone 8 app.

I get the following error:

'waitait' requires the type 'Windows.Foundation.IAsyncOperation' to have a suitable GetAwaiter method. Do you miss the using directive for "System"?

In this line of code:

StorageFolder guidesInstallFolder = await Package.Current.InstalledLocation.GetFolderAsync(guidesFolder); 

My portable class library is for the .NET Framework 4.5, Windows Phone 8, and .NET for Windows Store apps.

I am not getting this error for this line of code in a clean Windows Phone 8 project, and I am not getting it in the Windows Store app, so I don’t understand why it will not work in my PCL.

GetAwaiter is an extension method in the WindowsRuntimeSystemExtensions class, which is located in System.Runtime.WindowsRuntime.dll. Using Object Browser, I see that this DLL is available in the .NET application component set for the Windows Store and in the Windows Phone 8 component, but not in the .NET Portable Subset. I just don’t understand why it won’t be in the Portable Subset if it is available on both of my target platforms.

+8
c # windows-store-apps async-await portable-class-library windows-phone-8
source share
2 answers

You need the Async setup package in NuGet here for async / await to work with this combination of targets.

UPDATE:

Try this (absurd) piece of code to see if it uses async / await correctly.

 public async void MyMethodAsync() { var req = WebRequest.Create(""); await req.GetRequestStreamAsync(); } 

However, even if you missed the first async/await problem, which is not available, the Package API you are calling is not available in the PCL.

+3
source share

I just do not understand why this will not be in the portable subset if it is available on both my target platforms.

A portable subset is not just all that is usual. Each PCL member exists intentionally, and is not a member.

If you are missing a profile, ask Microsoft to add it (via MSConnect or to the Q & A tab of the old-but-still-controlled PCL page ).

+1
source share

All Articles