dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.06k stars 1.73k forks source link

Visual Studio 17.11.5 causes Windows MAUI to break build #25160

Open jayhayman-hdd opened 6 days ago

jayhayman-hdd commented 6 days ago

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.

Image

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

Redth commented 6 days ago

Is your project specifying explicit versions of WindowsAppSDK and/or WebView2 nuget packages?

jayhayman-hdd commented 6 days ago

WindowsAppSDK 1.5.240802000.

No NuGet reference to WebView2.

Redth commented 6 days ago

I'm not able to reproduce this so far. Are you able to share a reproduction of it?

jayhayman-hdd commented 6 days ago

Sure no problem. I'll get someone on my team or me to sort this out ASAP.

manodasanW commented 6 days ago

For the RcwReflectionFallbackGenerator compiler issue, I am working on a fix in the source generator to address this and turn it into a warning instead, but I believe it only happens when there is either a direct or transitive dependency to an older version of the WebView2 package used together with WinAppSDK 1.5 which has the same WebView APIs.

niksedk commented 6 days ago

I have the same issue with this project: https://github.com/niksedk/subtitle-alchemist (and other projects as well)

One computer where I updated it just crashes, and another computer with no visual studio update it works fine.

I'm on Windows 11

Image

Event viewer:

Log Name:      Application
Source:        Application Error
Date:          09/10/2024 23.19.45
Event ID:      1000
Task Category: Application Crashing Events
Level:         Error
Keywords:      
User:          LAPTOP-JUSVDOJ0\nikse
Computer:      LAPTOP-JUSVDOJ0
Description:
Faulting application name: SubtitleAlchemist.exe, version: 1.0.0.0, time stamp: 0x66e80000
Faulting module name: CoreMessagingXP.dll, version: 10.0.26105.1010, time stamp: 0x3cb81cec
Exception code: 0xc000027b
Fault offset: 0x00000000000945b2
Faulting process id: 0x0x4550
Faulting application start time: 0x0x1DB1A90F11A77C6
Faulting application path: C:\git\subtitle-alchemist\src\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\AppX\SubtitleAlchemist.exe
Faulting module path: C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.5_5001.275.500.0_x64__8wekyb3d8bbwe\CoreMessagingXP.dll
Report Id: be9846d4-086d-46ad-8246-43034bfaee45
Faulting package full name: dk.nikse.subtitlealchemist_0.0.6.0_x64__f9j3vma71va8p
Faulting package-relative application ID: App
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="Application Error" Guid="{a0e9b465-b939-57d7-b27d-95d8e925ff57}" />
    <EventID>1000</EventID>
    <Version>0</Version>
    <Level>2</Level>
    <Task>100</Task>
    <Opcode>0</Opcode>
    <Keywords>0x8000000000000000</Keywords>
    <TimeCreated SystemTime="2024-10-09T21:19:45.0432328Z" />
    <EventRecordID>338880</EventRecordID>
    <Correlation />
    <Execution ProcessID="4668" ThreadID="1612" />
    <Channel>Application</Channel>
    <Computer>LAPTOP-JUSVDOJ0</Computer>
    <Security UserID="S-1-5-21-2051407611-681702476-311258538-1001" />
  </System>
  <EventData>
    <Data Name="AppName">SubtitleAlchemist.exe</Data>
    <Data Name="AppVersion">1.0.0.0</Data>
    <Data Name="AppTimeStamp">66e80000</Data>
    <Data Name="ModuleName">CoreMessagingXP.dll</Data>
    <Data Name="ModuleVersion">10.0.26105.1010</Data>
    <Data Name="ModuleTimeStamp">3cb81cec</Data>
    <Data Name="ExceptionCode">c000027b</Data>
    <Data Name="FaultingOffset">00000000000945b2</Data>
    <Data Name="ProcessId">0x4550</Data>
    <Data Name="ProcessCreationTime">0x1db1a90f11a77c6</Data>
    <Data Name="AppPath">C:\git\subtitle-alchemist\src\bin\Debug\net8.0-windows10.0.19041.0\win10-x64\AppX\SubtitleAlchemist.exe</Data>
    <Data Name="ModulePath">C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.5_5001.275.500.0_x64__8wekyb3d8bbwe\CoreMessagingXP.dll</Data>
    <Data Name="IntegratorReportId">be9846d4-086d-46ad-8246-43034bfaee45</Data>
    <Data Name="PackageFullName">dk.nikse.subtitlealchemist_0.0.6.0_x64__f9j3vma71va8p</Data>
    <Data Name="PackageRelativeAppId">App</Data>
  </EventData>
</Event>
JoeTomkinson commented 6 days ago

I am seeing the same issue with WinUI 3 projects. I am using the below due to migrating to .NET 8. This only started when I ran the VS2022 update.

<!-- Specifies the version of the Windows SDK package to use -->
<WindowsSdkPackageVersion>10.0.26100.38</WindowsSdkPackageVersion>
jayhayman-hdd commented 6 days ago

@niksedk - are you using Skia Sharp extended: xmlns:controls="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI" or anything like Lottie animations <controls:SKLottieView...?

If I remove the <controls:SKLottieView... control from my XMAL. then my application progresses.

Not sure if this is an issue with the package or the fact it's loading resources from Resources/Raw/Lottie. More investigation today.

Previously when running our app in debug mode for either Android or Windows, we'd sometimes, maybe once every 100 build-runs, MAUI will hang on our loading screen as if the debugger hasn't attached or can't progress. Since 17.11.5, instead of hanging it now show the detached debugger modal as in my screen shot in the OP. This now happens every time I build, unless I uninstall the app from the device and debug run again. Next time the debugger detaches I can't get past the loading screen again until I uninstall the debug app and re-build. This is "tentative assumption" at the moment from early testing, it may just be a combination of ways I was testing last night.

This might be a separate issue, I'll try to get more information today.

For ref:

Image

niksedk commented 6 days ago

I'm using this Skia: Image

jayhayman-hdd commented 6 days ago

@niksedk are any of your resources using Skia loaded or saved to Resources/Raw?

niksedk commented 6 days ago

I do not think so... but I'm not entirely sure - you can check the source code: https://github.com/niksedk/subtitle-alchemist

manodasanW commented 6 days ago

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 RcwReflectionFallbackGenerator issue with WebView will be fixed by https://github.com/microsoft/CsWinRT/pull/1816

niksedk commented 6 days ago

Thanks for the workaround, works.

Zhanglirong-Winnie commented 6 days ago

This issue has been verified using Visual Studio 17.11.5 (8.0.91 & 8.0.82 &8.0.70 ). Can repro on Windows platform. Unable to verify regression, an error will be reported if the version is lower than 8.0.71 https://github.com/niksedk/subtitle-alchemist

jayhayman-hdd commented 5 days ago

Can confirm adding

<CsWinRTRcwFactoryFallbackGeneratorForceOptOut>true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>

And

<PropertyGroup>
    <WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>
</PropertyGroup>

Has fixed the issue for now. However the SDK package didn't automatically update. On two machines, we did the following:

  1. Added the above to .proj file.
  2. Closed VS.
  3. Clean build.
  4. Deleted .bin / .obj folders.
  5. Ran dotnet restore.
  6. Opened VS and build,

Should we remove these elements from the .proj file when .Net 9 goes GA?

Redth commented 5 days ago

For the RcwReflectionFallbackGenerator compiler issue, I am working on a fix in the source generator to address this and turn it into a warning instead, but I believe it only happens when there is either a direct or transitive dependency to an older version of the WebView2 package used together with WinAppSDK 1.5 which has the same WebView APIs.

That would make sense, and then I suspect some folks are hitting this using packages like SkiaSharp.Views.Maui.Controls which transitively depends on an older Microsoft.WindowsAppSDK which then depends on an older Microsoft.Web.WebView2.

JORGEGO commented 5 days ago

Im my case the exception produce when I call : var location = await Geolocation.GetLocationAsync(request); Image

The exception is producing in Windows

$(TargetFrameworks);net8.0-windows10.0.26100.0

And the event Viewer:

Faulting application name: greenyng.mobile.business.Operator.exe, version: 1.0.0.0, time stamp: 0x66e80000 Faulting module name: CoreMessagingXP.dll, version: 10.0.26105.1010, time stamp: 0x3cb81cec Exception code: 0xc000027b Fault offset: 0x00000000000945b2 Faulting process id: 0x0x8538 Faulting application start time: 0x0x1DB1B3BC52E9A3C Faulting application path: C:\gm\greenyng.mobile\greenyng.mobile.business.Operator\bin\Debug\net8.0-windows10.0.26100.0\win10-x64\AppX\greenyng.mobile.business.Operator.exe Faulting module path: C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.5_5001.275.500.0_x648wekyb3d8bbwe\CoreMessagingXP.dll Report Id: 80be37be-17c7-424e-b6ae-97663e2ca396 Faulting package full name: f52ad300-c749-4793-9424-d6d77b0cc588_1.0.0.1_x649zz4h110yvjzm Faulting package-relative application ID: App

So my try catch not catch the exception!! I have the las version of all Visual studio....

sbloomztf commented 5 days ago

I have a similar issue with my builds since 17.11.5

1>C:\Users\--\Mobile\xxx\obj\xxx\net8.0-windows10.0.19041.0\win10-x86\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs(5,21,5,38): error CS0116: A namespace cannot directly contain members such as fields, methods or statements
1>C:\Users\--\Mobile\xxx\obj\xxx\\net8.0-windows10.0.19041.0\win10-x86\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs(5,39,5,60): error CS0116: A namespace cannot directly contain members such as fields, methods or statements
1>C:\Users\--\Mobile\xxx\obj\xxx\\net8.0-windows10.0.19041.0\win10-x86\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs(5,16,5,21): error CS1514: { expected
1>C:\Users\--\Mobile\xxx\obj\xxx\\net8.0-windows10.0.19041.0\win10-x86\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs(5,38,5,39): error CS1022: Type or namespace definition, or end-of-file expected
1>C:\Users\--\Mobile\xxx\obj\xxx\\net8.0-windows10.0.19041.0\win10-x86\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGlobalVtableLookup.g.cs(6,1,6,2): error CS1022: Type or namespace definition, or end-of-file expected

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:

<!--https://github.com/dotnet/maui/issues/25160-->
<CsWinRTRcwFactoryFallbackGeneratorForceOptOut>true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>

<WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>

Just for funsies, here's the full context... windows is a mess right now.

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
        <!--
        Windows Entry broken after 8.0.82
        https://github.com/dotnet/maui/issues/24783
        -->
        <MauiVersion>8.0.82</MauiVersion>

        <!--https://github.com/dotnet/maui/issues/25160-->
        <CsWinRTRcwFactoryFallbackGeneratorForceOptOut>true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>

        <WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>

    </PropertyGroup>
    <PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'">
        <MauiVersion>8.0.91</MauiVersion>
    </PropertyGroup>
ARiSoul commented 5 days ago

Same problem here, with not a single reference to any WebView, with no third party controls, nothing... A very simple project that I've started last week. After upgrading Visual Studio yesterday to 17.11.5, simply stopped working with multiple errors as described in the issue description.

Just to confirm, that simply adding \<WindowsSdkPackageVersion>10.0.19041.34\</WindowsSdkPackageVersion>\, solved the issue.

Thank you for the workaround.

JORGEGO commented 5 days ago

now it works, In my case was the version of I had a bigger one, thanks to Copilot I was suggested to downgrade to this version now it works

JogyBlack commented 3 days ago

The <WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion> workaround unfortunately does not work for me, as I am using latest MVVM Toolkit which requires version 10.0.19041.38 or later.

The only way I was able to successfully compile my small program was by adding <AllowUnsafeBlocks>True</AllowUnsafeBlocks>

reinierkops commented 1 day ago

I'm facing the same problem. But I have also incorrect generated codefiles, for example WinRTGlobalVtableLookup.g.cs which cause build errors.

stephenquan commented 1 day ago

To use the latest CommuintyToolkit.Mvvm on Windows you may need to set your WindowsSdkPackageVersion to a .41 version, see https://github.com/CommunityToolkit/dotnet/issues/893#issuecomment-2316705291

Sydney680928 commented 1 day ago

I have also incorrect generated codefiles, for example WinRTGlobalVtableLookup.g.cs which cause build errors.

gdamino commented 19 hours ago

Same here, after update to vs 17.11.5 program crash at startup. Any workarounds?

Edit:

As mentioned some post ago adding these lines to maui project resolved the issue:

`

true
    <WindowsSdkPackageVersion>10.0.19041.34</WindowsSdkPackageVersion>

`

But the problem is not resolved, some ms devs here have to figure out the problem and why MAUI projects stop to build every time Visual Studio is updated. I have a lot of "workarounds" on my project file...

spatialdude commented 9 hours ago

Strangely Visual Studio 2022 Preview 17.12.0 Preview 3.0 appears to work ok. This hints at the problem being more to do with Visual Studio 17.11.5 than MAUI? 🤔