简体   繁体   中英

.netstandard library and UniversalApiContract

I'm building a .NETStandard library (version 1.3), using async await inside the library works fine until i add a reference to Windows.Foundation.UniversalApiContract . After adding this reference i get errors on every await keyword inside my code

this is the error

'IAsyncAction' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncAction' could be found

this is the code i need to run

await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { OnUserChanged?.Invoke(user); });

removing the await keyword result in a working code, but i get this warning

Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

How can i solve this?

Make sure you have using System; at the top of your code file. That has the extension required to turn IAsyncAction to a Task .

If that doesn't work, try this statement (just to see if the code compiles and runs):

var a = CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => { OnUserChanged?.Invoke(user); });

await System.WindowsRuntimeSystemExtensions.AsTask(a);

If the above doesn't work for you, then try temporarily upgrading to .Net Standard 1.4 (again, just to see if it compiles and runs)

And if that doesn't work, then there might be something messed up with the library references.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM