microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.32k stars 676 forks source link

AOT fails with Dictionary<T, U> in 1.6 Experimental #9710

Closed veler closed 2 months ago

veler commented 4 months ago

Describe the bug

In WinApp SDK 1.6 Experimental with AoT turned ON, build fails when using a property or method that returns a Dictionary with a strong type.

C:\repo\MyApp\MyApp\obj\x64\Release\net8.0-windows10.0.22621.0\win-x64\intermediatexaml\WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGenericInstantiation.g.cs(1455,33,1455,53): error CS0234: The type or namespace name 'MyApp' does not exist in the namespace 'ABI' (are you missing an assembly reference?)

Steps to reproduce the bug

Project file:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
        <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
        <RootNamespace>WinRTGenericMissing</RootNamespace>
        <ApplicationManifest>app.manifest</ApplicationManifest>
        <Platforms>x86;x64;ARM64</Platforms>
        <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
        <PublishProfile>win-$(Platform).pubxml</PublishProfile>
        <UseWinUI>true</UseWinUI>
        <EnableMsixTooling>true</EnableMsixTooling>
        <WindowsSdkPackageVersion>10.0.22621.35-preview</WindowsSdkPackageVersion>
        <PublishAot>true</PublishAot>
    </PropertyGroup>

    <ItemGroup>
        <Content Include="Assets\SplashScreen.scale-200.png" />
        <Content Include="Assets\LockScreenLogo.scale-200.png" />
        <Content Include="Assets\Square150x150Logo.scale-200.png" />
        <Content Include="Assets\Square44x44Logo.scale-200.png" />
        <Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
        <Content Include="Assets\StoreLogo.png" />
        <Content Include="Assets\Wide310x150Logo.scale-200.png" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.0-prerelease.240602.1" />
        <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
        <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240531000-experimental1" />
        <Manifest Include="$(ApplicationManifest)" />
    </ItemGroup>

    <!--
    Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
    Tools extension to be activated for this project even if the Windows App SDK Nuget
    package has not yet been restored.
  -->
    <ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
        <ProjectCapability Include="Msix" />
    </ItemGroup>

    <!--
    Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
    Explorer "Package and Publish" context menu entry to be enabled for this project even if
    the Windows App SDK Nuget package has not yet been restored.
  -->
    <PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
        <HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
    </PropertyGroup>
</Project>

And a C# file:

public class LearningData { }

public sealed partial class MainWindow : Window
{
    // This does not build.
    private async Task<Dictionary<string, LearningData>> DoesNotBuild()
    {
    }

    // This does build however.    
    private async Task<Dictionary<string, int>> DoesNotBuild()
    {
    }
}

Expected behavior

Get it to build.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.6 Experimental 1: 1.6.240531000-experimental1

Windows version

Windows 11 (22H2): Build 22621

Additional context

The issue seems to reproduce with Dictionary<T, U> along with IReadOnlyDictionary<T, U>, and probably many others. It's interesting that using a value type on U makes it work.

Sergio0694 commented 4 months ago

Don't have triage permissions here, but this should be moved to https://github.com/microsoft/CsWinRT.

manodasanW commented 3 months ago

Dupe of https://github.com/microsoft/CsWinRT/issues/1638

Scottj1s commented 2 months ago

@veler thanks for reporting this. The issue has been fixed and will be available in the next preview release of the Microsoft.Windows.CsWinRT package.

cc: manodasanw