CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Changes made to a C++/WinRT component does not get proper C# projection generated with a WinUI 3 application

Open RobsonPontin opened this issue 1 year ago • 5 comments

Describe the bug We are evaluating an architecture which we generate C# projection from a C++/WinRT component using a WinUI 3 Application (consumer) instead of a C# library (wrapper around C++/WinRT). The main reason of this approach is just to avoid an extra C# projection library in our project (diagram option 1), and just reuse our application to do the CS projection generation work (diagram option 2).

image

The issue happens after we attempt to modify the C++/WinRT component (i.e. refactoring a WinRT type) which causes the C# projection to not be re-generated and then an unhandled exception in runtime.

Sample project: https://github.com/RobsonPontin/WinUI3/tree/main/WinUI3_GenCsProjection

NOTE: I don't see such issue for option 1 on the diagram (C# library projection).

To Reproduce

  1. Using the sample project above, open solution, build the WinUI 3 application and start debugging it
  2. At this point everything is expected to be working and the app should start. Now click on the button to run the code-behind in the click event, and it should execute without issues.
  3. Now stop debugger and perform a minor refactoring of the C++/WinRT component. It can be renaming the MyLuckyNumber property to MyLuckyNumber2 in the MyWinRtClass.idl
  4. Once the refactoring is done, try to build the solution, run the app and repeat step 2
  5. The application would cause an exception and complain about the property is invalid.

Expected behavior I would expect for any changes made to the C++/WinRT component to trigger a new update and new C# projection.

Version Info

  • Visual Studio Enterprise 2022 v17.4.4
  • Microsoft.Windows.CsWinRT: v2.0.1
  • Microsoft.Windows.SDK.BuildTools: v10.0.22621.755
  • Microsoft.WindowsAppSDK: v1.2.221116.1
  • .NET: net6.0-windows10.0.19041.0

RobsonPontin avatar Jan 23 '23 23:01 RobsonPontin