dotnet / dotnet/linker

Analyzer: Type used in PInvoke should report RUC on default constructor

Open
#2,116 0 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

```C#
void Test()
{
PInvokeWithResult();
}

// IL2026 - Foo
[DllImport("nonexistent")]
static extern ResultType PInvokeWithResult();

class ResultType {
[RequiresUnreferencedCode("Foo")]
public ResultType() { }
}
```

Types used in PInvoke are potentially instantiated by the runtime via default .ctors. Thus if the .ctor is annotated with RUC this should cause a warning.

This is probably a very low priority thing to fix in the analyzer, since this would be very uncommon.

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.