microsoft / microsoft/node-api-dotnet
Support exporting generic types and methods to JS from a .NET module
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- C#
- Stars
- 783
- Forks
- 80
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
The next code fails nodejs module generation with an error.
The code:
public class CollectionBase<T>
{
public CollectionBase()
{
}
public void Add(T item) { }
}
The error:
CSC : error NAPI1001: NotSupportedException : This method is not supported on signature types. at System.Reflection.Sig natureType.GetConstructors(BindingFlags bindingAttr) at Microsoft.JavaScript.NodeApi.Generator.SymbolExtensions.AsConst ructorInfo(IMethodSymbol methodSymbol) at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.ToArray() at Microso ft.JavaScript.NodeApi.Generator.ModuleGenerator.ExportType(SourceBuilder& s, ITypeSymbol type, String exportName) at Mi crosoft.JavaScript.NodeApi.Generator.ModuleGenerator.ExportModule(SourceBuilder& s, ITypeSymbol moduleType, IEnumerable`1 exportItems) at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.GenerateModuleInitializer(ISymbol moduleInitial izer, IEnumerable`1 exportItems) at Microsoft.JavaScript.NodeApi.Generator.ModuleGenerator.Execute(GeneratorExecutionCo ntext context) [ConsoleApp1.csproj]
Command:
dotnet clean
dotnet build-server shutdown
dotnet publish ConsoleApp1.csproj -r win-x64 -f net8.0
Version: 0.7.8
AOT is enabled
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the provided generic CollectionBase and the dotnet publish command. Start with SymbolExtensions.AsConstructorInfo and ModuleGenerator.ExportType from the stack trace; done means generic types and methods can be exported to the generated Node.js module without the NAPI1001 exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, node.js
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100