Open silkfire opened 9 months ago
Tagging subscribers to this area: @dotnet/interop-contrib See info in area-owners.md if you want to be subscribed.
Due to how we have structured our analysis engine, this is actually much more difficult to implement than it seems. (Our system is pluggable and more of an opt-in/"determine type is marshallable" model than an opt-out/"determine type is unmarshallable" model).
Moving this to .NET 10 for now.
Analyzer
Diagnostic ID: SYSLIB1051
Describe the improvement
The analyzer tells you if you're trying to marshal a
struct
whose fields are incompatible with theLibraryImport
(source generated P/Invoke added in .NET 7) attribute.It would be extremely useful if the analyzer informed the developer which specific fields are incompatible for marshalling.
Right now it just says
The type '<struct type>' is not supported by source-generated P/Invokes. The generated source will not handle marshalling of parameter 'pstruct'.
If you remove the offending field(s) from thestruct
, the error goes away.Describe suggestions on how to achieve the rule
Add to the description of the analyzer a list of let's say max 5 fields that are incompatible for marshalling. These are types that are not blittable, i.e. reference types, string, arrays and
bool
.Just as the current implementation, this should work recursively, i.e. be able to support nested structs; an unsupported field may be found in a deeper struct hierarchy but should still be reported.