Create C# dll and use method with powershell

Question:

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.

I need to invoke that method from Powershell, so I added the type

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?

Answer:

Your method should be static or you need to create an instance of that type (TestClass).

Last can be done using

Or in your specific case:

Source:

Create C# dll and use method with powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply