locked
Error 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine." when launching powershell script, but only when running from c#

    Question

  • Very strange problem. I have a powershell script that runs fine when launched from the powershell commandline. But when I run it from within c# I get the error above. I already tried installing the AccessDatabaseEngine, but it did not help. It fails on pipeline.Invoke()

    System.Management.Automation.Runspaces.Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();
                runspace.Open();
    
                using (System.Management.Automation.RunspaceInvoke runspaceInvoker = new System.Management.Automation.RunspaceInvoke(runspace))
                {
                    runspaceInvoker.Invoke("Set-ExecutionPolicy RemoteSigned");
    
                    System.Management.Automation.Runspaces.Pipeline pipeline = runspace.CreatePipeline();
                    string powershellScriptPath = System.Configuration.ConfigurationManager.AppSettings["MtpPowershellScriptPath"];
                    pipeline.Commands.AddScript(powershellScriptPath);
                    pipeline.Commands.Add("Out-String");
    
                    Collection<System.Management.Automation.PSObject> results = new Collection<System.Management.Automation.PSObject>();
                    try
                    {
                        results = pipeline.Invoke();
                    }
                    catch (Exception ex)
                    {
                        results.Add(new System.Management.Automation.PSObject((object)ex.Message));
                    }
    
                    runspace.Close();

    Tuesday, April 24, 2012 12:36 AM

Answers

  • Even closer now. I found this link, http://cornasdf.blogspot.com/2009/09/force-powershell-script-to-run-in-x86.html, that shows how to change the bit runtime for a script. It works great when launching the powershell script directly from commandline. However when I run it from c# it does not actually do anything. It runs, but there's no changes made and no exceptions thrown.

    UPDATE: Ok that actually works. I had some syntax issues in my powershell file for the path to another file that is used. So the method in the link does indeed work.

    • Edited by dharric72 Tuesday, April 24, 2012 1:38 PM
    • Marked as answer by dharric72 Tuesday, April 24, 2012 1:38 PM
    Tuesday, April 24, 2012 1:16 PM

All replies

  • Ok I'm getting closer I tried running my powershell script directly in 64bit mode and I got the same error. Is there a workaround for this? Currently we have to run our c# windows app in 64bit mode.

    • Edited by dharric72 Tuesday, April 24, 2012 12:53 AM
    Tuesday, April 24, 2012 12:49 AM
  • Even closer now. I found this link, http://cornasdf.blogspot.com/2009/09/force-powershell-script-to-run-in-x86.html, that shows how to change the bit runtime for a script. It works great when launching the powershell script directly from commandline. However when I run it from c# it does not actually do anything. It runs, but there's no changes made and no exceptions thrown.

    UPDATE: Ok that actually works. I had some syntax issues in my powershell file for the path to another file that is used. So the method in the link does indeed work.

    • Edited by dharric72 Tuesday, April 24, 2012 1:38 PM
    • Marked as answer by dharric72 Tuesday, April 24, 2012 1:38 PM
    Tuesday, April 24, 2012 1:16 PM
  • Hi,

    Or you could just download and install the version you need from http://www.microsoft.com/download/en/details.aspx?id=13255 (as it exists in both a x86 and 64 bits version).

    If you still ahve an issue on Invoke, it would be best to tell exactly what it is...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Tuesday, April 24, 2012 1:29 PM
  • You can install both th e32-bit and the x86 version side by side.

    My blog: blog.jessehouwing.nl

    Wednesday, April 25, 2012 2:23 PM