Description
The node-api-dotnet
native host throws an exception if its initialize()
function is called multiple times in the same process:
.NET is already initialized in the current process. Initializing multiple .NET versions is not supported.
Normally a JS require()
will return the same object if called more than once for the same module path. But multiple initializations can happen for either of two reasons:
- Multiple .NET TFMs are requested in the same process, e.g.
require('node-api-dotnet/net6.0')
andrequire('node-api-dotnet/net7.0')
. - The module is required (with the same path) from multiple JS workers. Each worker initializes the module separately.
The first case is a valid error, since, as the error message says, multiple .NET versions in the same process are not supported.
But the second case should work. The native host can check if the same .NET version is requested and if so the re-initialization can be allowed. Then the managed host should use a separate assembly load context for each worker.