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 several indexers #271

Closed alexeybut closed 2 months ago

alexeybut commented 2 months ago

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

CSC : error NAPI1001: AmbiguousMatchException : Ambiguous match found for 'Class2 .Item this[] [Int32]'.   at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)   at System.Type.GetProperty(String name, BindingFlags bindingAttr)   at Microsoft.JavaScript.NodeApi.Generator.SymbolExtensions.AsPropertyInfo(IPropertySymbol propertySymbol)   at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.ExportProperty(SourceBuilder& s, IPropertySymbol property, String exportName)   at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.ExportMembers(SourceBuilder& s, ITypeSymbol type)   at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.ExportType(SourceBuilder& s, ITypeSymbol type, String exportName)   at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.ExportModule(SourceBuilder& s, ITypeSymbol moduleType, IEnumerable`1 exportItems)   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();
        }

        public Item this[string 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 

Linked with #270