microsoft / node-api-dotnet

Advanced interoperability between .NET and JavaScript in the same process.
MIT License
426 stars 49 forks source link

Unable to generate node module from C# class with an indexer #270

Closed alexeybut closed 2 months ago

alexeybut commented 2 months ago

Hello, Generating nodejs module with AOT for a class with indexer raises the error:

CSC : error NAPI1001: InvalidOperationException : Sequence contains more than one element   at System.Linq.ThrowHelper.ThrowMoreThanOneElementException()   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Boolean& found)   at Microsoft.JavaScript.NodeApi.Generator.ExpressionExtensions.ToCS(Expression expression, String path, HashSet`1 variables)   at Microsoft.JavaScript.NodeApi.Generator.ExpressionExtensions.FormatStatement(Expression expression, Boolean isReturn, String path, HashSet`1& variables)   at Microsoft.JavaScript.NodeApi.Generator.ExpressionExtensions.FormatBlock(BlockExpression block, String path, HashSet`1 variables)   at Microsoft.JavaScript.NodeApi.Generator.ExpressionExtensions.ToCS(Expression expression, String path, HashSet`1 variables)   at Microsoft.JavaScript.NodeApi.Generator.ExpressionExtensions.ToCS(Expression expression, String path, HashSet`1 variables)   at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.GenerateCallbackAdapters(SourceBuilder& s)   at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.GenerateModuleInitializer(ISymbol moduleInitializer, IEnumerable`1 exportItems)   at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.Execute(GeneratorExecutionContext context) [ConsoleApp1.csproj]

Code to reproduce:

    [JSExport]
    public class Class2
    {
        public Item this[int index]
        {
            get => throw new NotImplementedException();
            set => throw new NotImplementedException();
        }
    }

    [JSExport]
    public class Item
    {

    }

Version: 0.7.2 Command:

dotnet publish -c Release -r win-x64 -f net8.0