2
2
// Licensed under the MIT License.
3
3
4
4
using System ;
5
+ using System . Reflection ;
5
6
using System . Runtime . InteropServices ;
6
7
7
8
namespace Microsoft . JavaScript . NodeApi . Runtime ;
@@ -25,25 +26,29 @@ public sealed class NodejsPlatform : IDisposable
25
26
/// <summary>
26
27
/// Initializes the Node.js platform.
27
28
/// </summary>
28
- /// <param name="libnodePath">Path to the `libnode` shared library, including extension .</param>
29
+ /// <param name="libnode">Name of the `libnode` shared library.</param>
29
30
/// <param name="args">Optional application arguments.</param>
30
31
/// <param name="execArgs">Optional platform options.</param>
31
32
/// <exception cref="InvalidOperationException">A Node.js platform instance has already been
32
33
/// loaded in the current process.</exception>
33
34
public NodejsPlatform (
34
- string libnodePath ,
35
+ string libnode ,
35
36
string [ ] ? args = null ,
36
37
string [ ] ? execArgs = null )
37
38
{
38
- if ( string . IsNullOrEmpty ( libnodePath ) ) throw new ArgumentNullException ( nameof ( libnodePath ) ) ;
39
-
40
39
if ( Current != null )
41
40
{
42
41
throw new InvalidOperationException (
43
42
"Only one Node.js platform instance per process is allowed." ) ;
44
43
}
45
44
46
- nint libnodeHandle = NativeLibrary . Load ( libnodePath ) ;
45
+ var entryAssembly = Assembly . GetEntryAssembly ( ) ;
46
+
47
+ nint libnodeHandle =
48
+ entryAssembly == null
49
+ ? NativeLibrary . Load ( libnode , entryAssembly , null )
50
+ : NativeLibrary . Load ( libnode ) ;
51
+
47
52
Runtime = new NodejsRuntime ( libnodeHandle ) ;
48
53
49
54
Runtime . CreatePlatform ( args , execArgs , ( error ) => Console . WriteLine ( error ) , out _platform )
0 commit comments