Skip to content

Load assembly from module base path before trying to load from GAC - #8073

Merged
Travis Plunk (TravisEz13) merged 2 commits into
PowerShell:masterfrom
adityapatwardhan:LoadAssembly
Nov 5, 2018
Merged

Load assembly from module base path before trying to load from GAC#8073
Travis Plunk (TravisEz13) merged 2 commits into
PowerShell:masterfrom
adityapatwardhan:LoadAssembly

Conversation

@adityapatwardhan

Copy link
Copy Markdown
Member

PR Summary

When a binary module has the module assembly in GAC, we load the assembly from GAC before trying to load it from module base path.

This change attempts to load it from module base path before looking up in GAC.

PR Checklist

@adityapatwardhan

Copy link
Copy Markdown
Member Author

Steve Lee (@SteveL-MSFT) I guess this would technically be a breaking change if someone had a assembly with the same name in the module base folder and are relying on loading it from GAC instead. But, I believe that should be a very rare occurance. Your thoughts?

@SteveL-MSFT

Copy link
Copy Markdown
Member

Aditya Patwardhan (@adityapatwardhan) I can't imagine a scenario where a module author has an assembly in their module base folder but expects the assembly from the GAC to be loaded

@TravisEz13 Travis Plunk (TravisEz13) added the Breaking-Change breaking change that may affect users label Oct 19, 2018
@TravisEz13

Copy link
Copy Markdown
Member

Technically it's breaking, let's document it as breaking, but I don't think this needs committee review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we already got the resolved assembly path, we can skip the loading, right? The loading is solely for getting the path of the assembly. When the target assembly is in GAC, we have to load it in order to get the path, but not if we already resolved the assembly file path.

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.

In this case, we actually want to load from module base first. In the Resolve method, we do not have access to module base so we need to do this here. If there are alternatives, please suggest.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a comment to the code so it is clear to other developers that we really want to load the assembly here, not just return the pathname. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a comment to the code so it is clear to other developers that we really want to load the assembly here, not just return the pathname. Thanks!

@adityapatwardhan

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw) Please have another look.

@anmenaga

Copy link
Copy Markdown

Steve Lee (@SteveL-MSFT) Aditya Patwardhan (@adityapatwardhan) Here is example scenario: servicing a multi-version module.
Let's say there is a widely-used module that over time released several versions.
Then someone discovers a security bug in .NET that requires a client-side code fix from module authors.
It's a lot easier to put a fixed DLL into GAC than try to update DLL in all module version folders.

Aditya Patwardhan (@adityapatwardhan) is there an issue for this PR? did somebody complain?

@SteveL-MSFT

Copy link
Copy Markdown
Member

Andrew (@anmenaga) the real world scenario is that we have Windows partners that also ship their modules on PSGallery. The PSGallery version that the user explicitly installed may be newer than the one that is inbox. Currently, importing the module loads the older assembly in the GAC which doesn't match the updated module.

@anmenaga

Copy link
Copy Markdown

Steve Lee (@SteveL-MSFT) That's a valid scenario.
Though ideally, I think, the load order should be configurable. Is it something that can be placed in a config file?

@SteveL-MSFT

Copy link
Copy Markdown
Member

Andrew (@anmenaga) The updated one in the GAC may not be compatible with modules that were tested against a specific version. I think this is the tradeoff of app-local versions of assemblies. At this time, I don't think we should solve this problem universally.

@adityapatwardhan

Copy link
Copy Markdown
Member Author

Travis Plunk (@TravisEz13) Assigning this to you as I would like to get this in the next release.

@TravisEz13
Travis Plunk (TravisEz13) merged commit b5ab2dd into PowerShell:master Nov 5, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
…owerShell#8073)

[Breaking Change]
When a binary module has the module assembly in GAC, we load the assembly from GAC before trying to load it from module base path.

This change attempts to load it from module base path before looking up in GAC.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants