Skip to content

Do not use [Out] string for P/Invokes #35692

Description

@elinor-fung

Add a rule to flag P/Invoke declarations passing string parameters by value with the [Out] attribute, which can destabilize the runtime if the string is an interned string.

 // Flag [Out] string
[DllImport("MyLibrary")]
private static extern void Foo([Out] string s);

// OK
[DllImport("MyLibrary")]
private static extern void Bar(out string s1, [Out] ref string s2);

Category: Interoperability
Default: Enabled

cc @terrajobst @stephentoub @AaronRobinsonMSFT @jkoritzinsky

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions