Skip to content

Use the MetadataLoadContext to restore reflection-only type discovery for mechanisms like using assembly #6653

@rjmholt

Description

@rjmholt

See #3641. Types needed in PowerShell classes must be available at parse-time (i.e. not loaded with Import-Module or Add-Type) to be able to compile classes to IL.

To be able to resolve these types, we want to support the using assembly statement. However, the most available way to do this involves loading a DLL and possibly executing some of its code, presenting a vector for arbitrary code execution.

Instead, we should analyse a DLL's metadata to discover the types it exports, using a System.Reflection.Metadata.MetadataReader. Example code for this is in PR #3169. The entry point for this analysis would be the PowerShellModuleAssemblyAnalyzer class.

The right way to do this is now to use a MetadataLoadContext

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtimeWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions