microsoft / CsWinRT

C# language projection for the Windows Runtime
MIT License
539 stars 102 forks source link

SourceGenerator generates code using unsafe even if EnableUnsafeBlocks aren't enabled #1721

Closed manodasanW closed 1 week ago

manodasanW commented 2 weeks ago

Source generator generates code using unsafe even if EnableUnsafeBlocks isn't enabled. We probably should check if it is not enabled and given a better diagnostic asking EnableUnsafeBlocks to be enabled. If the CsWinRT package is referenced, this isn't an issue. But when the source generator is ran standalone as part of the projection package, it is.

WinRT.SourceGenerator\Generator.WinRTAotSourceGenerator\WinRTGenericInstantiation.g.cs(680,31,680,54): error CS0227: Unsafe code may only appear if compiling with /unsafe

manodasanW commented 2 weeks ago

It is also seems for the system classes, we sometimes generate code when we don't need to like the string class as we see it as a valid winrt type but it technically isn't a winrt projected class.