1

I created a .NET library and I want to create a GUI that calls the library via PowerShell. In order to call cmdlet I had to add an entry to Windows registry, because that library is compiled against .NET 4.

It works fine, but not for a PowerShell host in GUI. What can I do to set up PowerShell host to run a CLR 4 snap-in?

var rsConfig = RunspaceConfiguration.Create();
var myAssembly = new AssemblyConfigurationEntry("AssemblyName", "C:\...\Assembly.dll");
rsConfig.Assemblies.Append(myAssembly);
var runSpace = RunspaceFactory.CreateRunspace(rsConfig);
runSpace.Open();

using (var ps = PowerShell.Create()) {
    ps.Runspace = runSpace;
    ps.AddCommand("Get-MyCmdlet");
    ps.AddParameter("Param1");
    ps.AddParameter("Param2");
    foreach (var result in ps.Invoke()) { // CommandNotFoundException
        Debug.WriteLine(result.ToString());
    }
}

1 Answer 1

1

Problem solved. It was a little bit complicated. I wrote an article about it. Basically appending an assembly is a wrong approach. The easier way is register that assembly.

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

Comments

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.