Methods attributed with LibraryImportAttribute are implicitly unsafe. Although the marshalling logic could be analyzed to be considered memory-safe, the compiler cannot validate that the underlying extern DllImport is targeting a method with a valid signature.
Today, the stubs generated by LibraryImportGenerator will not generate the RequiresUnsafeAttribute on the produced stubs. This causes inconsistency with stubs that have no marshalling (they are just a raw DllImport, which is extern).
The LibraryImportGenerator should add the RequiresUnsafeAttribute to all generated stubs to provide a consistent experience.
Methods attributed with
LibraryImportAttributeare implicitly unsafe. Although the marshalling logic could be analyzed to be considered memory-safe, the compiler cannot validate that the underlyingexternDllImportis targeting a method with a valid signature.Today, the stubs generated by
LibraryImportGeneratorwill not generate theRequiresUnsafeAttributeon the produced stubs. This causes inconsistency with stubs that have no marshalling (they are just a rawDllImport, which isextern).The
LibraryImportGeneratorshould add theRequiresUnsafeAttributeto all generated stubs to provide a consistent experience.