Run a COM based c# console application from Windows Service (c#)

-1

I have a problem with running a c# console application from windows service application by c# code.

I use windows service as a background worker that runs a task (Quartz library) every time interval.

Here a code of job that runs other c# console app

ps = new ProcessStartInfo(batchRunnerPath);
ps.UseShellExecute = false;
ps.CreateNoWindow = true;
ps.RedirectStandardError = true;
ps.RedirectStandardOutput = true;
ps.Verb = "runas";
var process = Process.Start(ps);
string error = process.StandardError.ReadToEnd();
process.WaitForExit();

Console application is using COM objects and it renders PDF's and Images but it doenst matter.

When i run console app exe file manualy it works perfectly but when i try to run it from this worker i get an exception

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {22FBECF5-10A3-11D2-9194-204C4F4F5020} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
   at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
   at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
   at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at JDA.Intactix.Automation.SpacePlanning..ctor(Boolean bIKSBRVMenuParam)
   at ReportRunner.Program.Main(String[] args) in E:\CFT\PgRunner\BatchRunner\Program.cs:line 98

From what i see this worker is starting this console app (because i log some info with log4net in console app) but on line 98 where i create new COM object it gives error.

heres how i run windows service enter image description here

and heres a code that gives arror - line = new SpacePlaning(false) gives arror

      SpacePlanning sp = null;
        ProSpace.Project currentProject = null;
        ProSpace.PrintSetup printSetup = null;

        var plnLogic = Container.Resolve<Strategix.sCentralPlugin.SPPlugin.SPLogic.IPlanogramLogic>();

        try
        {
            sp = new SpacePlanning(false);
c#
windows
service
com
asked on Stack Overflow Feb 2, 2017 by Kamil • edited Feb 2, 2017 by Kamil

1 Answer

0

Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE))

might come from a not well defined Security/Identity configuration of the COM component you want use. You need enough rights in order to instanciate a COM component from a Windows service (rights management).

  • Launch DCOMCNFG.exe, Component Services -> Computers -> My Computer -> DCOM Config -> [Your COM component]
  • Right click, properties

Check "Security" tab and "Identity" tab configurations.

answered on Stack Overflow Feb 2, 2017 by Jeandey Boris

User contributions licensed under CC BY-SA 3.0