我創建了一個嘗試啓動應用程序的Windows服務(在本例中爲CATIA)。C#Windows服務COM異常80080005啓動應用程序時
我使用下面的代碼:
private Application GetApplicationObject(string ProgId)
{
Application AppObject = null;
//Try to get allready open instance of the Application
try
{
AppObject = (Application)Marshal.GetActiveObject(ProgId);
}
catch
{
//Create a new instance of the Application instead
AppObject = (Application)Activator.CreateInstance(Type.GetTypeFromProgID(ProgId));
}
return AppObject;
}
我收到以下錯誤,當我服務的嘗試啓動應用程序:
System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {87FD6F40-E252-11D5-8040-0010B5FA1031} failed due to the following error: 80080005. at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache) at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at CATIA.CATIA.GetApplicationObject(String ProgId)
重要:當我運行這段代碼作爲一個Windows應用程序,而不是的Windows服務的一切工作正常。我也試着首先啓動CATIA並讓它在後臺運行,但我的服務無法捕捉到它。
我使用本地系統運行服務,並且選中了「與桌面交互」框。
我的ProgId是CATIA.Application,正如我所說的,當我將它作爲應用程序而不是服務運行時,它可以工作。
什麼是造成這種情況的任何想法?