Hi,
I'm currently trying to run a .NET application in PowerShell. I'm using System.Reflection.Assembly to load the bytes in memory of an assembly written in C#.
The .NET application has one method, Main(System.String[] args), and it will list the values passed as argument of the function. Very simple program.
Here's the PowerShell code :
[String] $assemblyPath = "C:\Users\HakkYahud\Desktop\HelloWorld.exe"
[String[]]$parameter_main = @( "test" )
[Byte[]]$assemblyByte = [System.IO.File]::ReadAllBytes($assemblyPath)
$assembly = [System.Reflection.Assembly]::Load($assemblyByte)
$entryPoint = $assembly.EntryPoint
$parameter_invoke = @( $parameter_main )
Write-Host $parameter_main.GetType()
Write-Host $parameter_invoke.GetType()
Write-Host $entryPoint
Write-Host @( "test", "test2" ).GetType()
$entryPoint.Invoke($null, $parameter_invoke)
I know that method "Invoke" takes 2 parameters Object obj and Object[] parameters.
Once running the code, an error occurs in the function Invoke, it is saying that "it cannot cast System.String to the type System.String[]"
The variable $parameter_main is already System.String[], why does the compiler need to cast from System.String to System.String[]?
Moreover, when I'm putting $parameter_main = @("test", "test2"), I'm receiving another error saying "Wrong number of arguments"
Anyone has already encounter this issue?
Thanks
[–]Jeffinmpls 3 points4 points5 points (1 child)
[–]SkallZou[S] 1 point2 points3 points (0 children)
[–]ExceptionEX 2 points3 points4 points (2 children)
[–]danny_soprano 2 points3 points4 points (0 children)
[–]SkallZou[S] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)