dotnet / dotnet/linker

Unable to use xml to suppress warnings in a method with a modreq parameter

Open
#2,006 7 comments 0 reactions 0 assignees View on GitHub
area-Linker: Diagnostic
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

ASP.NET has the [following method](https://github.com/dotnet/aspnetcore/blob/52eff90fbcfca39b7eb58baad597df6a99a542b0/src/Components/WebAssembly/JSInterop/src/WebAssemblyJSRuntime.cs#L60):

```C#
protected override void EndInvokeDotNet(DotNetInvocationInfo callInfo, in DotNetInvocationResult dispatchResult)
{
// For failures, the common case is to call EndInvokeDotNet with the Exception object.
// For these we'll serialize as something that's useful to receive on the JS side.
// If the value is not an Exception, we'll just rely on it being directly JSON-serializable.
var resultOrError = dispatchResult.Success ? dispatchResult.Result : dispatchResult.Exception!.ToString();

// We pass 0 as the async handle because we don't want the JS-side code to
// send back any notification (we're just providing a result for an existing async call)
var args = JsonSerializer.Serialize(new[] { callInfo.CallId, dispatchResult.Success, resultOrError }, JsonSerializerOptions);
BeginInvokeJS(0, "DotNet.jsCallDispatcher.endInvokeDotNetFromJS", args, JSCallResultType.Default, 0);
}
```

This results in the following IL:

```
.method family hidebysig virtual
instance void EndInvokeDotNet (
valuetype [Microsoft.JSInterop]Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo callInfo,
[in] valuetype [Microsoft.JSInterop]Microsoft.JSInterop.Infrastructure.DotNetInvocationResult& modreq([System.Private.CoreLib]System.Runtime.InteropServices.InAttribute) dispatchResult
) cil managed
{
```

I'm trying to add an xml warning suppression for this method because it is calling into JsonSerializer (which is `RequiresUnreferencedCode`). However, all combinations of signatures I can try don't appear to work. When I pass `--generate-warning-suppressions xml` to the linker, it spits out the following format:

```xml



ILLink
IL2026
member
M:Microsoft.JSInterop.WebAssembly.WebAssemblyJSRuntime.EndInvokeDotNet(Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo,Microsoft.JSInterop.Infrastructure.DotNetInvocationResult& modreq(System.Runtime.InteropServices.InAttribute))

```

But this doesn't work. In other cases that use `in` parameters, I had to append `@` after the type name, but that doesn't work. Neither does dropping the `modreq` part in the string.

Debugging into it, it appears that Cecil is returning the modreq as part of the TypeReference.Name:

![image](https://user-images.githubusercontent.com/8291187/116625341-13fec780-a90f-11eb-8023-9c820b3d261b.png)

And for some reason, that string isn't matching in our parsing logic.

cc @vitek-karas

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.