Skip to content

MarshalingPInvokeScanner doesn't see [DisableRuntimeMarshalling] attributes in any assembly except System.Runtime.dll #112980

Closed
@rolfbjarne

Description

@rolfbjarne

The MarshalingPInvokeScanner task doesn't see [DisableRuntimeMarshalling] attributes defined in any assembly except System.Runtime.dll (where the attribute is defined).

The problem is that this code:

foreach (CustomAttributeHandle attrHandle in mdtReader.CustomAttributes)
{
CustomAttribute attr = mdtReader.GetCustomAttribute(attrHandle);
if (attr.Constructor.Kind == HandleKind.MethodDefinition)
{
MethodDefinitionHandle mdh = (MethodDefinitionHandle)attr.Constructor;
MethodDefinition md = mdtReader.GetMethodDefinition(mdh);
TypeDefinitionHandle tdh = md.GetDeclaringType();
TypeDefinition td = mdtReader.GetTypeDefinition(tdh);
if (mdtReader.GetString(td.Namespace) == "System.Runtime.CompilerServices" &&
mdtReader.GetString(td.Name) == "DisableRuntimeMarshallingAttribute")
return false;
}
}

does not take into account that the attribute's constructor will be a MethodReference when referencing a constructor defined in another assembly.

Repro:

This happens:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Interop-monoin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions