microsoft / CsWinRT

C# language projection for the Windows Runtime
MIT License
553 stars 106 forks source link

Authoring generator throws Win32Exception for methods with WindowId parameters #1428

Open Sergio0694 opened 10 months ago

Sergio0694 commented 10 months ago

Describe the bug

Just noticed the following failure when using WindowId as a parameter for a method:

"CSC : warning CS8785: Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'Win32Exception' with message 'Incorrect function'."

To Reproduce

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
    <Platforms>x64;ARM64</Platforms>
    <CsWinRTComponent>true</CsWinRTComponent>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.0.4" />
  </ItemGroup>
</Project>
using Windows.UI;

namespace MinimalWinRTComponentTest;

public sealed partial class MyClass
{
    public void Test(WindowId id)
    {
    }
}

Expected behavior

Should work fine..?

Version Info

Sergio0694 commented 10 months ago

Mmh actually this seems to be failing even with no parameters at all. Not exactly sure what's going on 🤔

dongle-the-gadget commented 10 months ago

Update: Initial suspect is correct, you need to specify CsWinRTWindowsMetadata. Otherwise it won't be able to find Windows.UI.WindowId. Not sure about the case when you don't specify a parameter though.

Can reproduce. Initial suspect is that you didn't specify CsWinRTWindowsMetadata. Turning on detailed verbosity to be sure. (scratch that, turns out you need to set CsWinRTEnableLogging to get generator logs)