Skip to content

Powershell Assembly Load Contexts Sample Code Doesn't Compile #8481

@microalps

Description

@microalps

Prerequisites

  • Write a descriptive title.
  • Search the existing issues.
  • I am reporting the documentation problem for version of PowerShell I am using.

Version

7.2

Link to affected document

https://docs.microsoft.com/en-us/powershell/scripting/dev-cross-plat/resolving-dependency-conflicts?view=powershell-7.2

Description of the documentation error

  1. AlcModuleAssemblyLoadContext does not handle if the file to load is not in the path. In this case it should return null and not LoadFromAssemblyPath. In my test, this was triggering an error about System.Runtime not being found.
  2. AlcModuleResolveEventHandler OnRemove signature is incorrect and is missing the PSModuleInfo argument. See https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.imoduleassemblycleanup.onremove?view=powershellsdk-7.0.0#System_Management_Automation_IModuleAssemblyCleanup_OnRemove_System_Management_Automation_PSModuleInfo_

Suggested fix

Add the following for #1

            if (!File.Exists(assemblyPath))
                return null;

Change the line with OnRemove to:

public void OnRemove(PSModuleInfo psModuleInfo)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions