-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Building with SDK 8.0.403 unexpectedly generates WinRT-related code #44026
Comments
Set |
Thanks @AliveDevil, I can confirm that setting this property works around the issue for our affected projects |
I can confirm this fix works |
So what's the deal here? Is it ok to disable the optimizer or should the warnings be fixed? Why is this enabled by default even when no other trimmer option is enabled in the project? And how many of those trimmer options is dotnet going to introduce? There are already so many that no one can remember them. |
Hopefully, they'll make this Opt-In to all the interfaces you want exposed to WinRT/AOT: microsoft/CsWinRT#1814 |
CsWinRT1028 is being generated for simple classes. Ex: Create an empty class, implement IDispose, and the warning will be generated. IMO, foundational interfaces should not be triggering this. Neither AOT nor trimming was enabled in that test case. |
The fix by @AliveDevil worked for me too. For others, I saw this issue in another variety, error logs were not clear, as with the original post WinRTGlobalVtableLookup.g.cs was mentioned.
|
Posting this to hopefully help others that start seeing this. I am not certain of the OP issue, but on a relatively simple personal hobby project I am working on I started to see these error when compiling:
My C# WinForms app and libs do not explicitly use WinRT (they do pinvoke some user32.dll calls). I found this issue and then microsoft/CsWinRT#1814. I edited my .csproj file to add
The problem went away. I changed The problem came back. I will be leaving |
None of the proposed solution in the linked issues doesn't work for me. The only thing that worked was to uninstall .net sdk 8.0.403 |
Same as @ekalchev here - the issue occurs with .NET SDK 8.0.403, and I double checked with a diagnostic build log that CsWinRTAotOptimizerEnabled was properly set to false, it simply has no effect: the WinRT source generator keeps getting called, wasting a good 30 seconds doing nothing useful in our builds. This commit between 8.0.402 and 8.0.403 appears to be the relevant: ec0ad19 |
Tagged @Sergio0694 and @manodasanW for follow-up - Sergio said this should be fixed soon but they may have more details. |
Is there a temporary hack? I literally edited |
We found a temporary hack. We've explicitly removed the Microsoft.Windows.SDK.NET.Ref framework reference in one of our core csproj files by adding this:
Since we apparently don't need Microsoft.Windows.SDK.NET.Ref and it was getting added automatically, removing it works around the issue entirely. CsWinRTAotOptimizerEnabled does seem to be set to false properly, but Microsoft.Windows.SDK.NET.Ref appears to be ignoring it. |
Why did you have to do this? Was setting |
Exactly, setting CsWinRTAotOptimizerEnabled to false has no effect, we've tried every way possible, enabled diagnostic logging to ensure it was set to false, and even went as far as modifying Microsoft.NET.Windows.targets directly to force it to false. Our conclusion is that CsWinRTAotOptimizerEnabled is simply ignored by Microsoft.Windows.SDK.NET.Ref |
I can confirm that settings CsWinRTAotOptimizerEnabled = false on the project that emit the error doesn't help |
To work around this issue, I initially uninstalled .NET SDK 8.0.403. However, when I set up a new development machine with a fresh Visual Studio installation, it automatically installed the latest SDK, which is 8.0.403. This led to the same build issue. Unfortunately, I cannot uninstall SDK 8.0.403 this time because it was installed via Visual Studio. Windows requires uninstallation through the Visual Studio Installer, but this process tries to remove all dependent components, including .NET Desktop Development. Essentially, there is no workaround for a new Visual Studio installation. I have been struggling with this for two days and am out of ideas on how to resolve it. |
For the people like me that cannot uninstall SDK 8.0.403. Here workaround I found. <Target Name="DisableWinRTSourceGenerator" BeforeTargets="CoreCompile">
<ItemGroup>
<Analyzer Remove="@(Analyzer)"
Condition="'%(FileName)%(Extension)' == 'WinRT.SourceGenerator.dll'"/>
</ItemGroup>
</Target> |
Has this been acknowledged as an issue by anybody from Microsoft yet? We're quite a few people that can confirm this really is an issue, and workarounds are required to regain build performance. @Sergio0694 |
@awakecoding, @baronfel from Microsoft is looking at this. He asked me for logs. See my response in the other issue here #44145 |
Any update on this? I'm getting CS0436, CsWinRT1028, CS0618 and CS0108 errors when opening a project using CsWinRT that has worked fine earlier. |
@abbweiman What version of CsWinRT are you using? Can you try the latest version on NuGet? Also, do you happen to have a reference (direct or transitive) to WinAppSDK? If so, can you try the latest version for that too. Most of the known issues discussed in this bug are resolved in CsWinRT 2.2.0 which I expect should be the default in next month's .NET SDK servicing update. |
@manodasanW Ah yes, it works after upgrading to 2.2.0. Thanks. |
Any word on how to address this with .NET MAUI? |
Describe the bug
After updating the .NET SDK from 8.0.402 to 8.0.403, some projects that target net8.0-windows10.0.19041.0 have started generating unexpected WinRT-related code via source generator WinRT.SourceGenerator.
The generated code uses language features only available in C# 9+, which in this case causes compilation to fail, but the main issue is that this source generator generates anything at all: this is not a project that uses WinRT, and with SDK 8.0.402 this doesn't happen.
Additionally, we are seeing diagnostics
CsWinRT1028
andCsWinRT1030
, which we do not see with 8.0.402.To Reproduce
See https://github.com/chris-white-wtw/dotnet-sdk-winrt-issue.
Using SDK 8.0.403, build test.csproj.
Exceptions (if any)
No exceptions, just a compilation error:
Further technical details
dotnet --info
:No particular IDE - running from command line.
The text was updated successfully, but these errors were encountered: