Witam, tworzę aplikację w .NET (c#) która ma być usługą systemową. Na razie stworzyłem banalny szkielet tworzący instancję GT i uruchamiający subiekta. Gdy tą samą funkcjonalność odpalam jako WindowsApplication to wszystko działa poprawnie natomiast gdy jest to WindowsService to dostaję następujący wyjątek: Creating an instance of the COM component with CLSID {F8605331-7454-4A45-98DB-A69EBB3D2947} from the IClassFactory failed due to the following error: 8000ffff. Czy ma ktoś z was jakiś pomysł jak to rozwiązać?
Poniżej przykładowy kod który powoduje problem.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
namespace WindowsServiceDemo
{
public partial class Service1 : ServiceBase
{
InsERT.GT gt;
InsERT.Subiekt subiekt;
public Service1()
{
InitializeComponent();
try
{
this.gt = new InsERT.GT(); // TUTAJ SIĘ WYWRACA
this.gt.Produkt = InsERT.ProduktEnum.gtaProduktSubiekt;
this.gt.Serwer = @".\INSERTGT";
this.gt.Autentykacja = InsERT.AutentykacjaEnum.gtaAutentykacjaMieszana;
this.gt.Uzytkownik = "sa";
this.gt.UzytkownikHaslo = "";
this.gt.Baza = "Demo";
this.gt.Operator = "Szef";
this.gt.OperatorHaslo = "";
}
catch (Exception ex)
{
this.WriteEventToWindowsLog("SubiektService", ex.Message);
}
}
protected override void OnStart(string[] args)
{
try
{
this.subiekt = (InsERT.Subiekt)gt.Uruchom(0, (int)InsERT.UruchomEnum.gtaUruchomWTle);
this.subiekt.Okno.Widoczne = false;
}
catch (Exception ex)
{
this.WriteEventToWindowsLog("SubiektService", ex.Message);
}
}
protected override void OnStop()
{
try
{
this.subiekt.Zakoncz();
}
catch (Exception ex)
{
this.WriteEventToWindowsLog("SubiektService", ex.Message);
}
}
public void WriteEventToWindowsLog(string strMyApp, string strEvent)
{
if (!System.Diagnostics.EventLog.SourceExists(strMyApp))
System.Diagnostics.EventLog.CreateEventSource(strMyApp, "Application");
EventLog MyEventLog = new EventLog();
MyEventLog.Source = strMyApp;
MyEventLog.WriteEntry(strEvent, EventLogEntryType.Warning);
}
}
}