22// Licensed under the MIT License.
33
44using System ;
5+ using System . Reflection ;
56using System . Runtime . InteropServices ;
67
78namespace Microsoft . JavaScript . NodeApi . Runtime ;
@@ -25,25 +26,29 @@ public sealed class NodejsPlatform : IDisposable
2526 /// <summary>
2627 /// Initializes the Node.js platform.
2728 /// </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>
2930 /// <param name="args">Optional application arguments.</param>
3031 /// <param name="execArgs">Optional platform options.</param>
3132 /// <exception cref="InvalidOperationException">A Node.js platform instance has already been
3233 /// loaded in the current process.</exception>
3334 public NodejsPlatform (
34- string libnodePath ,
35+ string libnode ,
3536 string [ ] ? args = null ,
3637 string [ ] ? execArgs = null )
3738 {
38- if ( string . IsNullOrEmpty ( libnodePath ) ) throw new ArgumentNullException ( nameof ( libnodePath ) ) ;
39-
4039 if ( Current != null )
4140 {
4241 throw new InvalidOperationException (
4342 "Only one Node.js platform instance per process is allowed." ) ;
4443 }
4544
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+
4752 Runtime = new NodejsRuntime ( libnodeHandle ) ;
4853
4954 Runtime . CreatePlatform ( args , execArgs , ( error ) => Console . WriteLine ( error ) , out _platform )
0 commit comments