NTypewriter icon indicating copy to clipboard operation
NTypewriter copied to clipboard

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

Open christophdebaene opened this issue 1 year ago • 1 comments

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.

christophdebaene avatar Mar 18 '24 12:03 christophdebaene

We will see about that, officially only .net standard 2.0 and C# 7.3 are supported in the custom function.

NeVeSpl avatar Mar 19 '24 17:03 NeVeSpl