'Can't load executable from memory, VB.NET assembly

So basically, I'm trying to load exe file into memory and run its Main function.

It's coded in VB.NET and it has a Namespace called ConApp and a Module called MyModule

So far I've tried this in powershell:

$path = [path to exe]
$bytes = [IO.File]::ReadAllBytes($path)
[System.Reflection.Assembly]::Load($bytes)

And this is the output:

GAC    Version        Location
---    -------        --------
False  v4.0.30319

So I assume it's loaded here? And then when I try to call it like this:

[ConApp.MyModule]::Main()

I get this error:

Unable to find type [ConApp.MyModule].
At line:1 char:1
+ [ConApp.MyModule]::Main()
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (ConApp.MyModule:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Any ideas on how could I achieve the execution from memory? Thanks in advance.



Solution 1:[1]

The answer was actually simple, I wasn't calling the assemblyname first.

So it should've been:

[ConApp.ConApp.MyModule]::Main()

instead of:

[ConApp.MyModule]::Main()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brophein