Closed Redth closed 1 week ago
Is this also related to the latest VS update to 17.11.5? Since applying this update this evening, MAUI Windows no longer builds with many (33) errors all 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' Cylch.Atp.Maui.App (net8.0-windows10.0.19041.0) D:\hayman-dev\Cylch\Reseller\ATP\MAUI\Cylch.Atp.Maui.App\obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs
The type 'CoreWebView2AcceleratorKeyPressedEventArgs' 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) D:\hayman-dev\Cylch\Reseller\ATP\MAUI\Cylch.Atp.Maui.App\obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs
I've added the following PropertyGroup
as mentioned above but this only added an additional 7 compile errrors.
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'"">
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
</PropertyGroup>
@jayhayman-hdd can you open a new issue with more details and a repro? Thanks!
Is this also related to the latest VS update to 17.11.5? Since applying this update this evening, MAUI Windows no longer builds with many (33) errors all 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' Cylch.Atp.Maui.App (net8.0-windows10.0.19041.0) D:\hayman-dev\Cylch\Reseller\ATP\MAUI\Cylch.Atp.Maui.App\obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs
The type 'CoreWebView2AcceleratorKeyPressedEventArgs' 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) D:\hayman-dev\Cylch\Reseller\ATP\MAUI\Cylch.Atp.Maui.App\obj\Debug\net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs
I've added the following
PropertyGroup
as mentioned above but this only added an additional 7 compile errrors.<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'""> <WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion> </PropertyGroup>
@jayhayman-hdd in the issue you open, can you also comment on what version of Microsoft.Web.WebView2
package you have referenced if any and what version of Microsoft.WinAppSDK
package do you have referenced? WinAppSDK has in past versions included the WebView types but in their recent 1.6 version, they forwarded the types from its package to the new WebView package. But it seems you had access to the older WebView types for netcore3 from before that change and also the WinAppSDK version of them at the same time which I don't believe worked together until the 1.6 version.
That pre-existing issue is getting exposed by the code generated by RcwFallbackInitializer
which is meant to make sure older projections don't get trimmed unexpectedly. You can disable the RcwFallbackInitializer by setting the property CsWinRTRcwFactoryFallbackGeneratorForceOptOut
to true to get unblocked if you do not make use of the WebView2 types.
CsWinRTRcwFactoryFallbackGeneratorForceOptOut
leads to lots of
Generator.WinRTAotSourceGenerator\WinRTGenericInstantiation.g.cs(2531,31,2531,47): error CS0227: Unsafe code may only appear if compiling with /unsafe
CsWinRTRcwFactoryFallbackGeneratorForceOptOut
works, but don't combine it with <WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
:)
I haven't had a chance to test this today as the team has been wrapping up a prod release for a client tomorrow. If anyone has already opened this as a new issue, I'll happily add my experience to it tomorrow (Thursday), or I'll create a new issue. Just glad I set a policy for me to canary new releases before being applied to the team ;)
The project that failed to build (https://apps.microsoft.com/detail/9n5w2tkq5sf0?hl=en-gb&gl=GB / https://play.google.com/store/apps/details?id=com.assettrackerpro.capture&hl=en-GB) has been an early MAUI project from .Net 6 onwards (but I think I re-created the project from a blank MAUI .Net 7 template) that has been upgraded with each minor and major release so possibly it's picked up some cruft. Deploys to Windows 10, Windows 11, iOS and Android. This project is bit of a big one...
I have another MAUI project that's a bit smaller (https://www.ben-app.co.uk/) that was created a few months ago so I'll try that on my spare dev box at home tonight.
I have updated:
And it does not compile the AddWindows
method, it is as if it did not exist:
Raised a new issue here: https://github.com/dotnet/maui/issues/25160
@bdovaz have you actually installed .NET 9 RC2 release of the SDK and installed the corresponding new workloads?
While often the newer 'nuget' than the workload you have installed can be used in projects, it isn't always guaranteed to work that way. In this case I believe you will need the .NET 9 RC2 SDK plus dotnet workload install maui --version 9.0.100-rc.2.24503.1
to get the latest workloads for it.
@Redth ok, it's just that until now I was only consuming the preview package using the .NET 8 SDK but I see that I'm out of luck and I have to change the SDK. I will wait for the GA release then.
Thanks.
follow this and it throw new error: "Exception has been thrown by the target of an invocation" . i use Telerik trial
There have been some recent changes to .NET SDK for Windows introduce support for different projection profiles to be used as well as new roslyn analyzers introduced to help detect incompatibilities with your code and Native AOT. These changes can cause some issues with existing .NET MAUI projects but are generally easy to work around.
Given the complexity of how some of these pieces fit together there are a number of areas which will ship servicing fixes to address the issues:
- MAUI .NET 9 RTM workload with an updated WindowsAppSDK reference to 1.6.x (MAUI currently references 1.5.x)
- .NET 9 RTM SDK with fixes for overly eager analyzer execution, improved fallback profile package logic
- WindowsAppSDK 1.6 servicing update
There are some related issues for those interested to learn more:
- Known WinRT.SourceGenerator and CsWinRT issues microsoft/CsWinRT#1809
- [dotnet-sdk-9.0.100-rc.2.24474.11] paint.netcore build with errors about elements from Microsoft.Windows.SDK.NET are not found sdk#43707
- [dotnet-sdk-9.0.100-rc.2.24474.11] paint.netcore build with error "Missing partial modifier on declaration of type 'AffineTransform2DEffect3'; another partial declaration of this type exists" sdk#43746
- [dotnet-sdk-9.0.100-rc.2.24470.13] Fail to build Text-Grab App with CS0116, CS1514, CS1022, CS0118, CS0103 error . sdk#43680
- Source generator IsPartial check doesn't check parent classes microsoft/CsWinRT#1799
- Fixing multiple type definition issue and fixing NotifyCollectionChangedAction issue microsoft/CsWinRT#1816
More on AOT / Trimming support in Windows / CsWinRT:
- https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/stable-channel#native-aot-support
- https://github.com/microsoft/CsWinRT/blob/master/docs/aot-trimming.md
- Also see CsWinRT Release Notes
Warnings / Errors and Workarounds
There are a few examples of warnings/errors you may encounter below:
MVVMTKCFG0003 - This version of the MVVM Toolkit requires 'Microsoft.Windows.SDK.NET.Ref' version '10.0.19041.38' or later. Please update to .NET SDK 8.0.109, 8.0.305 or 8.0.402 (or later). Alternatively, use a temporary 'Microsoft.Windows.SDK.NET.Ref' reference, which can be done by setting the 'WindowsSdkPackageVersion' property in your .csproj file. For your project configuration, it is recommended to set the package version to '10.0.19041.41'.
Could not load file or assembly 'WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709'. The system cannot find the file specified.":"WinRT.Runtime, Version=2.1.0.0, Culture=neutral, PublicKeyToken=99ea127f02d97709
CS0433: The type 'TextDecorations' exists in both 'Microsoft.WinUI, Version=3.0.0.0, Culture=neutral, PublicKeyToken=de31ebe4ad15742b' and 'Microsoft.Windows.SDK.NET, Version=10.0.20348.38, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
To fix these errors, you can add a property to your .csproj file:
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'"">
10.0.19041.38 If you see an error similar to the one below, you will need to add a partial identifier to the class mentioned in the error due to a new analyzer detecting code which is not Native AOT compatible:
CsWinRT1028: Class 'MauiCommandBar' implements WinRT interfaces but isn't marked partial. Type should be marked partial for trimming and AOT compatibility if passed across the WinRT ABI.
WebView2 - Type exists in both WebView2.Core and Microsoft.WinUI
If you encounter an error similar to this:
net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs(1296,125,1296,137): error CS0433: 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'
You can set this property in your project for now:
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'"">
true There is already an associated PR with the fix: microsoft/CsWinRT#1816 which will be released in an upcoming servicing release.
I have a packaged WinUI 3 project that broke. Adding
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<WindowsSdkPackageVersion>10.0.19041.38</WindowsSdkPackageVersion>
</PropertyGroup>
got rid of the Unsafe code may only appear if compiling with /unsafe
message, but now I'm getting the error:
Severity Code Description Project File Line Suppression State
Error (active) MSB4044 The "ResolvePackageAssets" task was not given a value for the required parameter "TargetFramework". C:\Program Files\dotnet\sdk\8.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 266
My .csproj file has defined TargetFramework as:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
...
May be which depend on SkiaSharp like Telerik will cause this. When VS2022 ver 17.11.5 cant build maui i switch to Rider try to build it but it have the same. Roll back to previous version 17.11.4 saved me
If you encounter an error similar to this:
net8.0-windows10.0.19041.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.RcwReflectionFallbackGenerator\RcwFallbackInitializer.g.cs(1296,125,1296,137): error CS0433: 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'
You can set this property in your project for now:
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'"">
true There is already an associated PR with the fix: microsoft/CsWinRT#1816 which will be > released in an upcoming servicing release.
This doesn't resolve the issue. I'm dead in the water again. Also, there's a typo in the suggested workaround. There's an extra " after 'windows'.
@hunsra Can you post the error you are hitting? Is it the same as the WebView error above?
@hunsra Can you post the error you are hitting? Is it the same as the WebView error above?
Sure. It is not the same, as it doesn't refer to WebView2. In fact, it doesn't refer to any specific assembly. It's similar in that it relates to the WinRT.SourceGenerator on Windows:
D:\Repos\Concord\Concord\obj\Debug\net8.0-windows10.0.26100.0\win10-x64\intermediatexaml\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGenericInstantiation.g.cs(14,32,14,36): error CS0227: Unsafe code may only appear if compiling with /unsafe
The error message repeats 96 times with different values in the parentheses following ".g.cs". I tried the suggestion from @Redth above to add the following to the project file:
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<CsWinRTRcwFactoryFallbackGeneratorForceOptOut>true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>
</PropertyGroup>
However, that didn't resolve the issue. I had to remove the following from the project file as well, as suggested by @espenrl above:
<WindowsSdkPackageVersion>10.0.26100.41</WindowsSdkPackageVersion>
This was previously added by suggestion in the past to resolve a different build issue I had with a prior .NET MAUI release. However, now it will build with it removed. This .NET MAUI release seems to have also introduced other issues such as a new crash in XAML parsing on iOS that wasn't present before, but that's a different page in the saga.
This worked for me
<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.22621.0</TargetFrameworks>
<OutputType Condition="'$(TargetFramework)' != 'net8.0'">Exe</OutputType>
<!-- Versions -->
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<WindowsSdkPackageVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.22621.38</WindowsSdkPackageVersion>
<CsWinRTRcwFactoryFallbackGeneratorForceOptOut Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">true</CsWinRTRcwFactoryFallbackGeneratorForceOptOut>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefaultLanguage>en</DefaultLanguage>
</PropertyGroup>
I follow most of the instructions here but it still getting an error message after I attempt to build my MAUI application:
Please notice that the generated type is not part of my source code but auto generated
1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(71,25,71,45): error CsWinRT1028: Class 'XamlMetaDataProvider' implements WinRT interfaces but isn't marked partial. Type should be marked partial for trimming and AOT compatibility if passed across the ABI. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\src\UI\PointPerfect.IoT.UI\Platforms\Windows\App.xaml.cs(11,22,11,25): error CsWinRT1029: Class 'App' implements WinRT interface(s) IApplicationOverrides, IXamlMetadataProvider generated using an older version of CsWinRT. Update to a projection generated using CsWinRT 2.1.0 or later for trimming and AOT compatibility. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(71,25,71,45): error CsWinRT1029: Class 'XamlMetaDataProvider' implements WinRT interface(s) IXamlMetadataProvider generated using an older version of CsWinRT. Update to a projection generated using CsWinRT 2.1.0 or later for trimming and AOT compatibility. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(1718,20,1718,30): error CsWinRT1028: Class 'XamlMember' implements WinRT interfaces but isn't marked partial. Type should be marked partial for trimming and AOT compatibility if passed across the ABI. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(1718,20,1718,30): error CsWinRT1029: Class 'XamlMember' implements WinRT interface(s) IXamlMember generated using an older version of CsWinRT. Update to a projection generated using CsWinRT 2.1.0 or later for trimming and AOT compatibility. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(1437,20,1437,38): error CsWinRT1028: Class 'XamlSystemBaseType' implements WinRT interfaces but isn't marked partial. Type should be marked partial for trimming and AOT compatibility if passed across the ABI. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(1437,20,1437,38): error CsWinRT1029: Class 'XamlSystemBaseType' implements WinRT interface(s) IXamlType generated using an older version of CsWinRT. Update to a projection generated using CsWinRT 2.1.0 or later for trimming and AOT compatibility. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(1487,20,1487,32): error CsWinRT1028: Class 'XamlUserType' implements WinRT interfaces but isn't marked partial. Type should be marked partial for trimming and AOT compatibility if passed across the ABI. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md) 1>D:\teksoft\PointPerfect.net\artifacts\obj\PointPerfect.IoT.UI\debug_net8.0-windows10.0.22621.0\XamlTypeInfo.g.cs(1487,20,1487,32): error CsWinRT1029: Class 'XamlUserType' implements WinRT interface(s) IXamlType generated using an older version of CsWinRT. Update to a projection generated using CsWinRT 2.1.0 or later for trimming and AOT compatibility. (https://github.com/microsoft/CsWinRT/tree/master/src/Authoring/WinRT.SourceGenerator/AnalyzerReleases.Shipped.md)
@rodrigovaras Is your project marked as AOT compatible (either with PublishAot
or IsAotCompatible
) or do you have a CsWinRT package reference? I expect those to only show up as warnings in those scenarios otherwise it would just be info diagnostics. WinAppSDK 1.6 has addressed this to make sure the code it generates is generated as partial for these to not be seen for folks in those scenarios.
This should be resolved now with the release of .NET 9 GA
There have been some recent changes to .NET SDK for Windows introduce support for different projection profiles to be used as well as new roslyn analyzers introduced to help detect incompatibilities with your code and Native AOT. These changes can cause some issues with existing .NET MAUI projects but are generally easy to work around.
Given the complexity of how some of these pieces fit together there are a number of areas which will ship servicing fixes to address the issues:
There are some related issues for those interested to learn more:
More on AOT / Trimming support in Windows / CsWinRT:
Warnings / Errors and Workarounds
There are a few examples of warnings/errors you may encounter below:
To fix these errors, you can add a property to your .csproj file:
If you see an error similar to the one below, you will need to add a partial identifier to the class mentioned in the error due to a new analyzer detecting code which is not Native AOT compatible:
WebView2 - Type exists in both WebView2.Core and Microsoft.WinUI
If you encounter an error similar to this:
You can set this property in your project for now:
There is already an associated PR with the fix: https://github.com/microsoft/CsWinRT/pull/1816 which will be released in an upcoming servicing release.