MarshalingPInvokeScanner detects structs as non-blittable · Issue #112982 · dotnet/runtime (original) (raw)

Description

MarshalingPInvokeScanner says all structs as non-blittable.

Reproduction Steps

Expected behavior

Test case should succeed.

Actual behavior

Fails with:

[...]
Assembly /Users/rolf/test/dotnet/marshalling-scanner/customstruct/bin/Debug/net9.0/customstruct.dll requires marshal-ilgen for method .Class1:DoSomething (first pass).
❌ Failed, because some assemblies are incompatible
make: *** [customstruct] Error 1

Regression?

No

Known Workarounds

No response

Configuration

No response

Other information

This happens because there's no code here handling structs:

if (baseTypeHandle.Kind == HandleKind.TypeReference)
{
TypeReference baseType = reader.GetTypeReference((TypeReferenceHandle)baseTypeHandle);
if (reader.GetString(typeDef.Namespace) == "System" &&
reader.GetString(baseType.Name) == "Enum")
return Compatibility.Compatible;
}

The code should look at all instance fields of a struct, and if they're all blittable, then the struct is blittable too.