Skip to content

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

@vitek-karas

Description

@vitek-karas
        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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions