maui: Visual Studio 17.11.5 causes Windows MAUI to break build
Description
Following on from issue: https://github.com/dotnet/maui/issues/25132
Since installing 17.11.5, all of our MAUI builds are failing for Windows with errors along the lines of:
The type 'CoreWebView2' exists in both 'Microsoft.Web.WebView2.Core, Version=1.0.864.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e' and 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b' obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs
and
The type 'CoreWebView2HttpHeadersCollectionIterator' exists in both 'Microsoft.Web.WebView2.Core, Version=1.0.864.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e' and 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b' Cylch.Atp.Maui.App (net8.0-windows10.0.19041.0) \obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs
Project 1 is a large MAUI project built with .Net 7 MAUI project templates and upgraded with every new release.
Project 2 is a smaller MAUI project built a few months ago with .Net 8 MAUI project templates.
Both projects tested return the same amount of errors (33). with the same errors.
Neither of these projects are intentionally using WebView2 components that we are aware of.
Both projects target:
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>
And platform:
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
Project 1 has to target Windows 10 to keep compatibility with our customer.
What I’ve tried to fix this from suggestions in other posts
Adding…
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
</PropertyGroup>
Does not resolve any of the errors.
Adding…
CsWinRTRcwFactoryFallbackGeneratorForceOptOut
Removes all errors and both projects compile and run.
However, I am now getting a debugging attachment error in Project 1 when running my Windows app that does not appear on machines that have not been upgraded to 17.11.5.
I cannot tell yet if this is an error related to the 17.11.5 update (did anything MAUI based get updated in 17.11.5?) or a new issue for us. I will spend more time on it tomorrow. iOS and Android work as expected, it only seems to be a Windows issue - break points still work but I’ve not been able to determine what line in our code is causing this. I will update as I debug.
Adding both WindowsSdkPackageVersion and CsWinRTRcwFactoryFallbackGeneratorForceOptOut only outputs unsafe errors:
Unsafe code may only appear if compiling with /unsafe \obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGenericInstantiation.g.cs
When me and my team have some spare time, we’ll try to rebuild a repo for testing.
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
8.0.91 SR9.1
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.91 SR9.1
Affected platforms
Windows
Affected platform versions
net8.0-windows10.0.19041.0 / 10.0.17763.0
Did you find any workaround?
No response
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 9
- Comments: 41 (5 by maintainers)
If I use WindowsSdkPackageVersion with 10.0.19041.54 it’s ok !
CS1514 { attendue MY-COMETA (net8.0-windows10.0.19041.0) D:\GITHUB\COMETA_APPS\MY-COMETA\obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs 5
CS0116 Un espace de noms ne peut pas contenir directement des membres tels que des champs, des méthodes ou des instructions MY-COMETA (net8.0-windows10.0.19041.0) D:\GITHUB\COMETA_APPS\MY-COMETA\obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs 5
CS1022 Définition de type ou d’espace de noms, ou fin de fichier attendue MY-COMETA (net8.0-windows10.0.19041.0) D:\GITHUB\COMETA_APPS\MY-COMETA\obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs 6
I have a similar issue with my builds since 17.11.5
I have multiple similar projects sharing the same “core” project, of these, 2 have these build errors, another runs fine… I’ve tried a few of the mentioned work arounds without success so far.
Edit: Adding this to my project file has me back up and running:
Just for funsies, here’s the full context… windows is a mess right now.
There is now a new SkiaSharp build out on nuget that should be fixed!
I also encountered this issue a few days ago. Adding CsWinRTRcwFactoryFallbackGeneratorForceOptOut as mentioned above is working as a workaround for me
<CsWinRTRcwFactoryFallbackGeneratorForceOptOut>true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>I just investigated another similar issue related to Skia which it seems both repros here have too. See here for more details and a workaround until we fix it: https://github.com/dotnet/maui/issues/25150#issuecomment-2404428189
And the
RcwReflectionFallbackGeneratorissue with WebView will be fixed by https://github.com/microsoft/CsWinRT/pull/1816