Skip to content

Discover assemblies loaded by 'Assembly.Load(byte[])' and 'Assembly.LoadFile' - #12203

Merged
Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
daxian-dbw:assembly
Mar 28, 2020
Merged

Ilya (iSazonov) merged 2 commits into
PowerShell:masterfrom
daxian-dbw:assembly

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Mar 25, 2020 •

Copy link
Copy Markdown
Member

PR Summary

Fix #12052

Fix a regression in PS 7.0 introduced by #11088
PowerShell should discover assemblies loaded by Assembly.Load(byte[]) and Assembly.LoadFile as in prior versions.

Assemblies loaded by Assembly.Load(byte[]) and Assembly.LoadFile are placed in special AssemblyLoadContext instances of the type System.Runtime.Loader.IndividualAssemblyLoadContext. PowerShell should return assemblies from those load context instances.

Also include a minor change to ignore the .ionide folders, which are auto-generated by VS Code C# extension to hold symbol caches.

/cc Patrick Meinecke (@SeeminglyScience)

PR Checklist

@daxian-dbw Dongbo Wang (daxian-dbw) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Mar 25, 2020
Comment thread .gitignore Resolved
/// </summary>
private static IEnumerable<Assembly> GetPSVisibleAssemblies()
{
const string IndividualAssemblyLoadContext = "System.Runtime.Loader.IndividualAssemblyLoadContext";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is that IndividualAssemblyLoadContext is internal class and .Net is free to change the name.
Maybe more reliable to use an assembly context name ("Assembly.Load(byte[], ...)" and "Assembly.LoadFile({0})"). It is public contract and has one prefix Assembly.Load for both.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any one can create a ALC instance with the name "Assembly.Load(byte[], ...)" or "Assembly.LoadFile(".
It's less reliable to depend on the name than the type. They can change the type name, but I think that possibility is very low, and we have test to catch the failure if the type name really changes.

@iSazonov
Ilya (iSazonov) merged commit e741dc5 into PowerShell:master Mar 28, 2020
@iSazonov Ilya (iSazonov) changed the title Fix regression: pwsh should discover assemblies loaded by 'Assembly.Load(byte[])' and 'Assembly.LoadFile' Discover assemblies loaded by 'Assembly.Load(byte[])' and 'Assembly.LoadFile' Mar 28, 2020
@daxian-dbw
Dongbo Wang (daxian-dbw) deleted the assembly branch March 28, 2020 18:09
@ghost

Copy link
Copy Markdown

🎉v7.1.0-preview.2 has been released which incorporates this pull request.:tada:

Handy links:

@ghost

Copy link
Copy Markdown

🎉v7.0.1 has been released which incorporates this pull request.:tada:

Handy links:

John Dennis (silijon) pushed a commit to SkyKick/PowerShell that referenced this pull request Jul 2, 2020
…oadFile' (PowerShell#12203)

* Fix regression: pwsh should discover assemblies loaded by 'Assembly.Load(byte[])' and 'Assembly.LoadFile'
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…oadFile' (PowerShell#12203)

* Fix regression: pwsh should discover assemblies loaded by 'Assembly.Load(byte[])' and 'Assembly.LoadFile'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Powershell 7.x : Cannot use type from dll (built for netstandard2.0)

9 participants