question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Module Load and Unload Event

See original GitHub issue

Request

The PowerShell engine does not expose events for module authors to subscribe when a module load/unload event occurs. This causes module authors to implement workarounds to identify when a module is loaded/unloaded.

Add module load/unload events.

Background

I have a module that uses other modules to ship “providers” like the PSProvider system. PowerShell is able to inspect modules during load to identify if a module contains a PSProvider and add it to the internal cache of providers. PowerShell is also able to remove the PSProvider from the cache when the module is unloaded. Modules that leverage a provider model outside of the engine have to use workarounds to discover providers inside other modules.

PackageManagement does not import providers when a module is loaded but instead requires the user to call Import-PackageProvider to load the provider. If the module containing the provider is removed the provider is not removed and there is no command to remove it.

SHiPS requires the provider to use a specific naming convention for the SHiPS provider to load the script module provider.

Alternatives

PSModuleInfo.OnRemove

This can be used to inject logic into another module unload action but there is no protection against this logic from being wiped out from the module or other user.

IModuleAssemblyInitializer/IModuleAssemblyCleanup or Script Module

These run in the target module but have to implemented by the other module author.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:6
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
rjmholtcommented, Aug 21, 2020

+1 for a module load/unload event. There’s been quite a few times I’ve wanted this as well.

Yes I’ve also seen good reasons for wanting this, both in my own work and when others have asked. /cc @TylerLeonhardt.

I’m surprised we don’t already have an issue for this btw

1reaction
ThomasNietocommented, Aug 21, 2020

@iSazonov This issue is all about subscribing to module load/unload events in order to perform an action. I may not have been as clear as I wanted but “I have the cmdlets update a cache every time a cmdlet or completer is called.” is a workaround to not being able to subscribe to module load/unload events. I have logic in the cmdlet/completer to check which modules have been loaded/unload since the the last time the cache was updated. This wouldn’t be necessary if I was able to subscribe to module load/unload events directly.

I’ll update the description to have a better explanation and request to have module load/unload events.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module load/unload commands in Linux scripts
I often have a need to create Linux scripts which contain module load and module unload commands. Is there a way to test...
Read more >
How to List, Load, and Unload Software Modules
The module commands allow you to list, load, or unload software modules to tailor your environment to your needs. Listing Software Modules.
Read more >
Module load, progress, ready, setup and unload events
2. Load module using MXML. 3. Unloading a module using ActionScript. 4. Use multiple · Use multiple <mx:AddChild>.
Read more >
Kernel Modules Load and Unload Protection - TechDocs
When access is requested for a kernel module record, the requested access is either "load" or "unload". On all non-Linux systems, the name...
Read more >
How do I use Module Unload Callback?
The Module Unload callback is a user/system callback that is invoked when a YANG module is unloaded from the server. This callback is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found