Skip to content

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

Closed

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

Activity

  1. added
    untriaged
    in-pr
    on Feb 27, 2025
  2. removed
    untriaged
    on Mar 7, 2025
  3. locked and limited conversation to collaborators on Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Interop-monoin-pr

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions