/// <summary> /// Create a singleton of PowerShellAssemblyLoadContext. /// Then register to the Resolving event of the load context that loads this assembly. /// </summary> /// <remarks> /// This method is to be used by native host whose TPA list doesn't include PS assemblies, such as the /// in-box Nano powershell, the PS remote WinRM plugin, in-box Nano DSC and in-box Nano SCOM agent. /// </remarks> /// <param name="basePaths"> /// Base directory paths that are separated by semicolon ';'. /// They will be the default paths to probe assemblies. /// </param> public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)] string basePaths) { if (string.IsNullOrEmpty(basePaths)) { throw new ArgumentNullException(nameof(basePaths)); } PowerShellAssemblyLoadContext.InitializeSingleton(basePaths); }
/// <summary> /// Initialize a singleton of PowerShellAssemblyLoadContext. /// </summary> internal static PowerShellAssemblyLoadContext InitializeSingleton(string basePaths) { lock (s_syncObj) { if (Instance != null) { throw new InvalidOperationException(SingletonAlreadyInitialized); } Instance = new PowerShellAssemblyLoadContext(basePaths); return(Instance); } }