CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Fix invalid cast exception with stream APIs and make code fixer emit diagnostics as warnings

Open manodasanW opened this issue 1 year ago • 1 comments

  • Added a new CsWinRTAotWarningLevel property to control whether the warnings from the code fixer are emitted as warnings or info. By default, for scenarios involving non built-in types, they will be emitted as warnings and built-in types will be emitted as info. The property can be used to control that behavior.
  • Fix InvalidCastException when using the stream extension APIs. The stream extension APIs make use of generic types and AsyncInfo.Run, but given we disable the lookup table generation on the Windows SDK projection, they are not automatically made AOT safe. Due to that, adding a manual implementation of what would get generated and only initializing it from the stream scenarios so that other scenarios can just trim it if the stream extension APIs are not used.

Fixes #1634 Fixes #1649

manodasanW avatar Jul 01 '24 02:07 manodasanW

Thank you for trying to fix https://github.com/microsoft/CsWinRT/issues/1634. Unfortunately, I still see the same issue with this patch. Interestingly, if I copy StreamTaskAdaptersImplementation.cs to my application and make sure its Init() method has been called, it works.

lhak avatar Jul 01 '24 08:07 lhak

Thank you for trying to fix #1634. Unfortunately, I still see the same issue with this patch. Interestingly, if I copy StreamTaskAdaptersImplementation.cs to my application and make sure its Init() method has been called, it works.

Did you just use the updated WinRT.Runtime.dll or did you also build the Windows SDK projection? The stream changes are in the Windows SDK projection (Microsoft.Windows.SDK.NET.dll) so they will need that to be regenerated.

manodasanW avatar Jul 01 '24 08:07 manodasanW

Ok, I thought the updated code was in WinRT.Runtime.dll and I only used an updated cswinrt nuget package. So I guess everything will be fine once an updated Windows SDK nuget package is available.

lhak avatar Jul 01 '24 08:07 lhak