Skip to content

Host throws exception when initialized multiple times by JS workers #93

Closed
@jasongin

Description

@jasongin

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:

  1. Multiple .NET TFMs are requested in the same process, e.g. require('node-api-dotnet/net6.0') and require('node-api-dotnet/net7.0').
  2. 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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions