views:

493

answers:

3

I'm working on debugging a Powershell project. I'm using Import-Module to load the PS module from my C# dll and everything works fine. Calling Remove-Module does not fully unload the module though as the DLL is still locked and can not be deleted.

Is there a way to get PSH to fully unload the module and release the DLL so that I can copy over it and reload it again using Import-Module without restarting the PSH console?

Update
So if you load a module into a seperate AppDomain does it still work like a normal module? Can anyone provide an example?

+2  A: 

I believe this holds true for PowerShell: in the .NET world the only way to unload an assembly is to load it into a different AppDomain; once an assembly is loaded to an AppDomain it remains loaded for the lifetime of that AppDomain.


Here's an example from a thread asking pretty much the same question and showing a couple ways to create and load the module into a new AppDomain:

http://www.eggheadcafe.com/conversation.aspx?messageid=30789124&threadid=30766269

STW
I expected this may be the case, however I don't think you can load an interact with PSH modules this way. So the real answer is likely that what I'm trying to achieve is not possible.
spoon16
+4  A: 

No. As PowerShell uses .NET underneath it has the same requirements. You cannot unload a dll from a .NET AppDomain without unloading the AppDomain itself. As the PowerShell UI lives in the same AppDomain this is not possible.

Mischa
+1  A: 

Concerning AppDomains & PowerShell, I blogged about this some while ago:

http://www.nivot.org/2007/12/07/WhyAppDomainsAreNotAMagicBullet.aspx

-Oisin

x0n