I created a simple C# dll and registered it using RegAsm.exe
. One very simple method is invoked without parameters and returns a number, here is a simplified version.
namespace AVL_test {
interface ITestClass {
int GetNumber();
}
[ComVisible(true)]
public class TestClass: ITestClass {
public TestClass() { }
public int GetNumber() {
return 10;
}
}
}
I need to invoke that method from Powershell, so I added the type
Add-Type -Path "C:\myPath\AVL_test.dll"
It seems to be loaded because if I [AVL_test.TestClass]
I get this output
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False TestClass System.Object
But if I try to invoke GetNumber()
by typing[AVL_test.TestClass]::GetNumber()
I get this error
Method invocation failed because [AVL_test.TestClass] does not contain a method named 'GetNumber'.
Am I doing something wrong?
Your method should be static
or you need to create an instance of that type (TestClass).
Last can be done using
New-Object -TypeName <full qualified type name> -ArgumentList <args>
Or in your specific case:
$test = New-Object -TypeName AVL_Test.TestClass
$test.GetNumber()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With