Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #15684
rolfbjarne opened this issue Feb 27, 2025 · 0 comments · Fixed by #112981
Labels
area-Interop-mono in-pr There is an active PR which will close this issue when it is merged

Comments

@rolfbjarne
Copy link
Member

rolfbjarne commented Feb 27, 2025

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
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Feb 27, 2025
@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Feb 27, 2025
rolfbjarne added a commit to rolfbjarne/runtime that referenced this issue Feb 27, 2025
…Scanner.

Fix detecting the [DisableRuntimeMarshalling] attribute in
MarshalingPInvokeScanner for assemblies that reference the attribute from
another assembly (i.e. any assembly except System.Runtime.dll).

Fixes dotnet#112980.
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Interop-mono in-pr There is an active PR which will close this issue when it is merged
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants