uwp-desktop icon indicating copy to clipboard operation
uwp-desktop copied to clipboard

The type forwarder for type 'Windows.Foundation.IAsyncOperation`1' in assembly 'Windows' causes a cycle

Open bao-qian opened this issue 7 years ago • 15 comments

I'd like to use await with IAsyncOperation. after I added

c:\Program Files (x86)\Windows Kits\10\UnionMetadata\Facade\Windows.WinMD
c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll

I got:

The type forwarder for type 'Windows.Foundation.IAsyncOperation`1' in assembly 'Windows' causes a cycle

image

bao-qian avatar Aug 16 '16 18:08 bao-qian

Any updates on this?

JamesEarle avatar Apr 21 '17 19:04 JamesEarle

This issue is currently crushing my hopes and dreams.

TechnikEmpire avatar Mar 09 '18 08:03 TechnikEmpire

@JamesEarle @bao-qian the instructions in this repo and on the nuget site are wrong. You do not manually add the facade for the API you need. This is what causes the circular reference.

You simply add the full Windows.winmd at C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd and System.Runtime.WindowsRuntime. That's it. Note when I say "full", I mean the .winmd file should be a few megabytes. There's plenty of them with the same name sprinkled around that are a few kb and it's easy to screw up and select one of these.

Then, wherever you call await on an IAsyncOperation, make sure you have using System; in the same source file.

Hope this helps people.

TechnikEmpire avatar Mar 09 '18 12:03 TechnikEmpire

@TechnikEmpire Thank you for clarifying this! I had previously added the "Target Platform = 10" in the .csproj file, then added the UWP references as needed and hit the circular reference issue. Simply doing the two things you recommended fixed the issues (including getting the right version of the .winmd file).

duncanmacmichael avatar Apr 15 '18 00:04 duncanmacmichael

My class library starts to compile when I follow those steps too. But I'm trying to create a nuget package that provides an interface to facilitate a use case that several different WPF applications have that require the interaction with low energy bluetooth devices. When I run this code from a WPF application, I get a PlatformNotSupportedException thrown complaining about WinRT not being supported on "this" platform.

Is there anything I can do?

jakehockey10 avatar Dec 10 '18 18:12 jakehockey10

What is this host os and build number? Not that not all rt APIs are supported on all builds iirc.

TechnikEmpire avatar Dec 10 '18 18:12 TechnikEmpire

Give details about api as well

TechnikEmpire avatar Dec 10 '18 18:12 TechnikEmpire

image image image I wasn't sure if I was grabbing the right windows.winmd file, so I just grabbed the latest. Does this version matter? Do I need to go to the lowest common version depending on what I'm deploying to?

jakehockey10 avatar Dec 11 '18 00:12 jakehockey10

Someone else will have to answer that but my initial instinct would be that you ought to reference the lowest possible version.

TechnikEmpire avatar Dec 11 '18 01:12 TechnikEmpire

I'll give that a shot when I'm in the office. Thanks for responding!

jakehockey10 avatar Dec 11 '18 07:12 jakehockey10

@jakehockey10 Also make sure you see my remarks here.

TechnikEmpire avatar Dec 11 '18 17:12 TechnikEmpire

@TechnikEmpire Thanks for reaching out! Are you suggesting that I use the window.winmd file from the ...\10.0.16299.0\... path specifically? Also, when you mention System.Runtime.WindowRuntime, where are you pulling that in from? Your file system or the NuGet package?

jakehockey10 avatar Dec 11 '18 17:12 jakehockey10

I tried the most earliest version of windows.winmd on my file system and that was version 10.0.15063.0

jakehockey10 avatar Dec 11 '18 17:12 jakehockey10

I can't remember how I referenced windowsruntime, probably just the way the docs say.

TechnikEmpire avatar Dec 11 '18 18:12 TechnikEmpire

I also encountered this error but no luck with any of these solutions in this thread! :(

jcs090218 avatar Jul 27 '20 17:07 jcs090218