Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Microsoft.Windows.Compatibility to v3.0.0 Results in Build Errors #30996

Closed
nick-beer opened this issue Sep 27, 2019 · 8 comments
Closed

Comments

@nick-beer
Copy link
Contributor

I recently update my Microsoft.Windows.Compatibility nuget from v3.0.0-preview5.19224.8 to v3.0.0. After updating, I'm not longer able to build. The build generates many errors similar to:

File.cs(1814,20): error CS0012: The type 'IAsyncAction' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. [G:\Project.NetCore_015px2u3_wpftmp.csproj]

This error is repeated for IAsyncAction, IAsyncActionWithProgress<>, IAsyncOperation<>, and IAsyncOperationWithProgress<>.

The lines that are generating these errors are places that we are awaiting a custom object that contains a Task. That object has a GetAwaiter extension method that returns a TaskAwaiter - obtained from the contained Task.

The project's in question have Sdk="Microsoft.NET.Sdk.WindowsDesktop", and UseWpf and UseWindowsForms set to 'true'.

I've tried reproducing these build errors in a smaller application, but I haven't had any luck yet. I'll keep trying to reproduce, but in the meantime, does anyone have any ideas?

@nick-beer
Copy link
Contributor Author

When the GetAwaiter method is invoked as an extension method, I get the errors. If I call it directly as a static method, there' is no error:
image

@nick-beer
Copy link
Contributor Author

Finally figured out how to reproduce the error. See here: https://github.com/nick-beer/GetAwaiterBug. Adding a using statement for 'System' was the step I had previously been missing. I suspect it has something to do with these extension methods?

@safern
Copy link
Member

safern commented Sep 27, 2019

The real problem is the System.Runtime.WindowsRuntime package, which is included in the new Compatibility package, which was actually included post preview5, that is why you didn't hit the issue in preview5. dotnet/corefx@687ec69

I'll dig a little bit more to see why this is happening, it seems like a facade might be broken, but still not sure.

@safern
Copy link
Member

safern commented Sep 27, 2019

Ok, so I think the way to go here is to remove the System.Runtime.WindowsRuntime reference from the compat pack as it really not needed by our main customers when including the compat pack into their projects.

However, this seems like a compiler bug because no-one is using those extension methods at all, if you compile it by including Windows.md using the WinRT meta-package, it will succeed, but looking at the producing assembly, it doesn't even have a reference to System.Runtime.WindowsRuntime, so the fact that is being passed as a reference to the compiler is what is causing this to fail. /cc: @jaredpar

As a workaround add this package reference to your project:

<PackageReference Include="System.Runtime.WindowsRuntime" Version="4.6.0" ExcludeAssets="all" />

@danmosemsft we would need to remove the reference to System.Runtime.WindowsRuntime from the compat pack, so I will mark this as 3.0 to service it.

@danmoseley
Copy link
Member

@safern does this need a 3.0 PR?

@safern
Copy link
Member

safern commented Oct 1, 2019

@safern does this need a 3.0 PR?

Yes, I will port dotnet/corefx#41419 now

@Tragetaschen
Copy link
Contributor

@safern
With regards to the compiler, this looks similar to dotnet/roslyn#18673 (or dotnet/roslyn#27107). The compiler considers the method for overload resolution even though it's not used. At least that's my understanding.

@safern
Copy link
Member

safern commented Oct 10, 2019

Closing as we removed S.R.WindowsRuntime* from the compat pack. The roslyn question/issue I will follow up with their team to see if there needs to happen something on their side.

@safern safern closed this as completed Oct 10, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0.x milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants