-1

I am trying to execute a custom action method from power-shell here is the code I have written in c#

namespace MyCustomAction
{
    public class CustomActions
    {
       [CustomAction]
        public static Session TestResult(Session session)
        {
            session["name"] = "hello";
            return session;
        }
    }
}

After building t he solution here is how I am loading the assemblies

[System.Reflection.Assembly]::LoadFile("C:\Program Files (x86)\WiX Toolset v3.10\SDK\Microsoft.Deployment.WindowsInstaller.dll")

[System.Reflection.Assembly]::LoadFile("D:\CustomAction\\bin\x86\Debug\MyCustomAction.dll") | Out-Null

But I am not getting how to pass session to the method as required I tried the following but no luck

$session = [Microsoft.Deployment.WindowsInstaller.Session]
[MyCustomAction.CustomActions]::TestResult($session)
2

1 Answer 1

0

If you are trying to create a new object of your class, you can use the New-Object

$session = New-Object [Microsoft.Deployment.WindowsInstaller.Session]

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/new-object

Sign up to request clarification or add additional context in comments.

3 Comments

Getting following error New-Object : Cannot find type [[Microsoft.Deployment.WindowsInstaller.Session]]: verify that the assembly containing this type is loaded
Sorry, you don't need to give the square bracket "[" for your type $session = New-Object Microsoft.Deployment.WindowsInstaller.Session
Then I am getting following error New-Object : A constructor was not found. Cannot find an appropriate constructor for type Microsoft.Deployment.WindowsInstaller.Session.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.