Skip to content

Using C# 9.0 init accessors in a custom function gives an error inside Visual Studio extension #111

@christophdebaene

Description

@christophdebaene

When using init accessors or primary constructors on records inside a custom (*.nt.cs) function

public class Sum
{
    public int X { get; init; }
    public int Y { get; init; }
}

Or

public record Sum(int X, int Y)

Gives the following error

error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported

To fix the error you need to add the following code inside the custom function.

namespace System.Runtime.CompilerServices
{
    [EditorBrowsable(EditorBrowsableState.Never)]
    internal static class IsExternalInit { }
}

It would be great if this can be added automatically by the Visual Studio extension itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions