High-performance in-proc interop between .NET and JavaScript
github.com/microsoft/node-api-dotnet Jason Ginchereau @jasongin Vladimir Morozov @vmoroz
First-class in-proc interopability between .NET and JavaScript
.NET and JavaScript are widely used, and often complementary, but there is not a great interop story between them.
While some limited solutions exist, there are opportunities to do better in many ways!
Requirements:
const dotnet =require('node-api-dotnet'); dotnet.Console.WriteLine('Hello from .NET!'); const MyAssembly = dotnet.load('path/to/MyAssembly.dll'); const myObj = new MyAssembly.MyClass(...args);
Dynamic invocation has some limitations, e.g. some forms of generics, ref/out params. These can be reduced or eliminated with further development.
// C# [JSExport] public class MyClass { public MyClass(string[] args) { } }
// TypeScript import { MyClass } from 'my-package'; const myObj = new MyClass(...args);
Option: Use .NET Native AOT to avoid .NET Runtime dependency.
.NET app hosts Node.js or another JS engine in-proc, then uses interop capabilities for deep integration between .NET and JS code.
Calling Azure OpenAI from JavaScript using the .NET Semantic Kernel library
await
JSValue
JSObject
JSArray
JSMap
JSPromise
JavaScript or TypeScript code can reference type defintions for .NET APIs.
.d.ts
.NET / JS interop is fast because:
struct
Span<T>
stackalloc
Warm JS to .NET calls are nearly twice as fast when compared to edge-js using that project's benchmark.
edge-js
Numbers are microseconds. "Warm" is an average of 10000 .NET -> JS calls (passing a medium-size object).
Major development areas:
Project backlog: https://github.com/users/jasongin/projects/1
Use the Marp CLI or Marp for VS Code to generate slides from this markdown file: https://github.com/marp-team/marp-cli https://github.com/marp-team/marp-vscode