Friday, April 20, 2012

Accessing old Assemblies

By "Accessing old Assemblies" I don't just mean that I am looking at a .NET 1.1 assembly.  I mean, this is the project that I wrote when we bought a VS2003 license and tried to leave VB6 behind us "OLD".

Of specific issue, I have some assemblies that are built from source by our process and loaded in VB.NET as a script.  They really do what I use PowerShell for now for other areas as they define specific logic and call into a central assembly to do anything complicated.  An instance is created and the "script" is passed a class of configuration properties and told to run.  The parent application then waits for completion and relays results back to an MSMQ where a VB6 application relays the results to a user.

This is an old and patchwork approach.   So I want to be able to remove the VB6 app and the MSMQ and call these compiled "scripts" from Powershell.  The problem is that I can't just New-Object without a namespace....  and I really have no idea what the namespace is.

Fortunately Add-Type has a PassThru argument.  What comes out of this is an array of RuntimeType.  Unfortunately it is an array and not a hash table.  Fortunately PowerShell is built for this.


001
002
003
$ScriptAssembly = add-type -Path "D:\source\MyScript.dll" -pass
$MyScript = new-object $($ScriptAssembly | Where {$_.Name -eq "MyScriptBaseClass"})
$MyScript.Run()


Now I don't have to find the namespace, just the name that you see when you write-output.



Write-output $ScriptAssembly



No comments:

Post a Comment