Asked By l0b0
20-Sep-07 09:41 AM

Hi all,
I'm creating a custom DLL, but using
[System.Reflection.Assembly]::LoadFile("filename.dll")
results in a lock on the DLL file which is not released until I quit
PowerShell. This is a bit unfortunate, so I've had a look around (for
hours) trying to find a way to be able to unlock the file once the
script is done using it.
I've found three promising C# articles (none for PowerShell) on how to
do it. Here are the methods and results:
Sandboxing via application domains - <http://nickgrattan.wordpress.com/
2007/07/13/sandboxing-an-assembly/>.
Seems fine until I get to the step where remoteWorker is created. I've
got the following code, and I've no idea how to convert it to the
right type as in C#:
$instance = $domain.CreateInstanceFromAndUnwrap("${tempDir}
\CERNSharepointAdmin.dll", 'Admin', $false, 0, $null, $null, $null,
$null, $null)
Also,
gm -i $instance
does not list the methods which should be available in this object.
Custom application domains - <http://dotnetslackers.com/CSharp/
re-56561_App_Domains_and_dynamic_loading_the_lost_columns.aspx>.
Quite vague, and also relies on type casting the object from
CreateInstanceFromAndUnwrap.
Shadow copying - <http://bartdesmet.net/blogs/bart/archive/
2006/07/29/4146.aspx>.
I got stuck at
$assembly = $domain.Load('CERNSharepointAdmin', $null)
, where I invariably get one of the error messages "The system cannot
find the file specified" (when running as above) or "The given
assembly name or codebase was invalid" (when running with the absolute
file path instead of the file prefix).
If it's any help, the source file starts like this:
Class="CERN.SharePoint.Administration.Admin" %>
Have you successfully created code to load and unload DLLs in
PowerShell? Any help would be greatly appreciated!