Using Static Methods & Classes from External Dll in Compiled PowerShell 7 Script

Howdy @adam,

In my PowerShell 7 script I can access classes and methods for a .dll I’ve added using Add-Type, but when I compile an .exe using Merge-Script I receive an error. A sample of the error is:

This works when run in the terminal:


But when compiled I receive this error:

Exception calling “showError” with “2” argument(s): “Object reference not set to an instance of an object.”

It appears to me like Merge-Script is including my dll, although I can’t be sure, but I am not sure how to refer to it once it is bundled into my exe.

Thank you,
mason

I’d suggest trying to get some more info from the exception. The stack trace info may be good in trying to track down the problem.

try
{
  [Namespace.Class]::ShowError('error', 'text')
}
catch {
   $_.Exception | FL *
}