App work in console, not as windows service - c#

I have an app using COM library. When i run it to test in console app it works good. But when i install it as Windows Service using installutil. In logs i have error
Message: (SaveInvoice) - Zapisywanie faktury - FS/12584/2012/01
Nie znaleziono błedu o kodzie: Creating an instance of the COM component with CLSID {F8605331-7454-4A45-98DB-A69EBB3D2947} from the IClassFactory failed due to the following error: 8000ffff Katastrofalny błąd. (0x8000FFFF (E_UNEXPECTED)).
Stacktrace: SaveDocuments.SaveInputDocuments => SaveMethods.SaveInvoice => LogProvider.ErrorException
Exception:
System.Runtime.InteropServices.COMException (0x8000FFFF): Creating an instance of the COM component with CLSID {F8605331-7454-4A45-98DB-A69EBB3D2947} from the IClassFactory failed due to the following error: 8000ffff Katastrofalny błąd. (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)).
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 Rewizor.Application.Start.get_Gt()
at Rewizor.Application.Start.get_Rewizor()
at Rewizor.Parsers.Invoice.InvoiceParser.InvoiceParserVatDocument(CustEDIInvoice invoice)
at Rewizor.ModelRepository.Invoice.InvoiceRepository.CreateInvoice(CustEDIInvoice invoice)
at DALRewizor.RewizorRepository.CreateInvoice(CustEDIInvoice invoice)
at EDIService.BLL.RepositoryBLL.CreateInvoice(CustEDIInvoice invoice)
at BLL.InboxRepository.SaveMethods.SaveInvoice(EDI_OutputStorage item)
Anyone have idea, how to solve it?

One of the common problems in this scenario are user permissions, because the service runs as a different user than that who runs in console. But judging by the comments on the question, you already checked it.
Another source of errors is the fact that the working directory of the console application is the directory where the EXE is located. With Windows Services, it's not; the working directory is C:\Windows\System32 (or wherever %SYSTEMDIR% is). So, if you have code that relies on the current working directory (such as reading a file in the same directory), it will not work as a service. I'm not sure, but maybe the same problem could happen if you are trying to load a COM library in the same path as the EXE.
So, what I suggest you:
Double check your permissions.
Check any code that relies on relative paths and change it to absolute paths instead.

Related

C# 8000401a The server process could not be started because the configured identity is incorrect

I'm trying to use the office component to convert a excel file to a pdf file ,but I get the exception as blow
<exception><![CDATA[System.Runtime.InteropServices.COMException (0x8000401A): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password. (Exception from HRESULT: 0x8000401A).
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.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
]]></exception>
However,when I restart the IIS ,everything is ok.And almost two days later,The Exception appear again.

How to fix the error for the interop when you dont have microsoft office installed

I have this code on my service:
Application xlsApp = new Application();
xlsApp.Visible = false;
Workbook wb = xlsApp.Workbooks.Open(dictionaryPath);
Sheets sheets = wb.Worksheets;
Worksheet ws = (Worksheet)sheets.get_Item(1);
var numberOfRows = ws.UsedRange.Columns["A"].Rows.Count;
var firstCol = ws.Range[dictionaryColumn + "1:" + dictionaryColumn + numberOfRows];
values = firstCol.Value as Array;
And when I run because I don't have Microsoft Office installed on my server I get this error:
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
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)
And I know that one of the solutions is to install the Microsoft Office but I am not allowed to do that so is there any other way to access the excel and not to install Microsoft Office. I use COM Interop and it is included in the project I also tried installing Open XML SDK 2.5 but for some reasons it didn't work. Can some one help me find a solution

Lost uCommerce interface within Sitecore

I am developing a web application using SiteCore 8 and uCommerce. To configure uCommerce I go through Sitecore and load the uCommerce interface. This morning I tried to load the uCommerce interface in the normal way, i.e logged into Sitecore and loaded uCommerce, but got nothing more than a white screen in Sitecore. Looking at the browser console I can see 2 different 500 errors:
Failed to load resource: the server responded with a status of 500
(Internal Server Error)
http://local.myapp.co.uk/ucommerceapi/Content/undefined/RootNode
Failed to load resource: the server responded with a status of 500
(Internal Server Error)
http://local.myapp.co.uk/ucommerceapi/Localization/TranslatedStrings
Failed to load resource: the server responded with a status of 500
(Internal Server Error)
http://local.myapp.co.uk/ucommerceapi/Content/tree/RootNode Failed to
load resource: the server responded with a status of 500 (Internal
Server Error)
If I click on the url in the error I get a page that displays:
Server Error in '/' Application.
Value cannot be null. Parameter name: EndpointHost.Config
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: EndpointHost.Config
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentNullException: Value cannot be null. Parameter name:
EndpointHost.Config]
[ConfigurationErrorsException: ServiceStack: AppHost does not exist or
has not been initialized. Make sure you have created an AppHost and
started it with 'new AppHost().Init();' in your Global.asax
Application_Start()]
ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory..cctor()
+836
[TypeInitializationException: The type initializer for
'ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory' threw
an exception.]
ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory..ctor()
+0
[TargetInvocationException: Exception has been thrown by the target of
an invocation.] System.RuntimeTypeHandle.CreateInstance(RuntimeType
type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +159
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,
Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
+256 System.Activator.CreateInstance(Type type, Boolean nonPublic) +127 System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture,
Object[] activationAttributes, StackCrawlMark& stackMark) +14297981
System.Activator.CreateInstance(Type type, BindingFlags bindingAttr,
Binder binder, Object[] args, CultureInfo culture, Object[]
activationAttributes) +198 System.Activator.CreateInstance(Type
type, BindingFlags bindingAttr, Binder binder, Object[] args,
CultureInfo culture) +28
System.Web.HttpRuntime.CreateNonPublicInstance(Type type, Object[]
args) +83 System.Web.Configuration.HandlerFactoryCache..ctor(String
type) +57 System.Web.HttpApplication.GetFactory(String type) +94
System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+375 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288
I have tried recreating the Global.asax, I have tried replacing all the sitecore folders:
sitecore
sitecore modules
sitecore_files
and the App_Config folder using files from a colleagues machine that is working fine but not luck. I can copy my colleagues solution to my PC and it works fine (except he has none of the work I have done)
Can anyone throw any light on what the problem might be?
In case anyone else stumbles on this problem. I deleted the website from IIS then recreated it and the problem has gone away. I have no idea why this has fixed the issue, as I have changed nothing in IIS for days.

System.IO.FileLoadException with WebService

I'm using Visual Studio 2013 and I am trying to create a webservice using the assembly DNSTools from Nuance SDK. My WebMethod is really simple : I just create an object from a DNSTools' class, then return "Hello World".
using DNSTools;
namespace WebTestFinal
{
public class WebServiceTestFinal : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
DgnDictCustom dgn = new DgnDictCustom();
return "Hello World";
}
However when I reach the line :
DgnDictCustom dgn = new DgnDictCustom();
It throws me this error :
System.IO.FileLoadException: Retrieving the COM class factory for component with CLSID {A0E850E3-91DB-11D1-96DC-0080C72FD13C} failed due to the following error: 8007045a. A dll initialization routine failed. (Exception of HRESULT : 0x8007045A).
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 WebTestFinal.WebServiceTestFinal.HelloWorld()
I did some research and found out that System.IO.FileLoadException was thrown because an assembly cannot be loaded. Despite using Fuslogvw.exe and Process Monitor I can't find which assembly is the root of the problem.
Go to Project Properties and in Build Tab, select X86 for platform target, and if it's already X86 change de to 64
In VS - project properties - in the Build tab - platform target =X86

How do I clone a OLE/COM registry entry for use with different settings

I have written a C# program that is to interface with Catia v5.18 via OLE/COM. It is going to be a common case where the machine the program is ran on will have multiple versions of Catia installed on it. Both older and newer and installed in any funky order. The last one installed gets to put its settings in the registry.
I'm trying to setup the registry to use a new handle to connect only to a 5.18 CNEXT server. I found the Catia.Application entry in HKEY_CLASSES_ROOT and the CLSID entry. I made copies of these and provided a new UUID for CLSID and came up with the following registry import file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\CATIA.Application.v518]
#="OLE CATIA.Application"
[HKEY_CLASSES_ROOT\CATIA.Application.v518\CLSID]
#="{ba3ca493-05fb-4188-a767-f40c03db2672}"
[HKEY_CLASSES_ROOT\CLSID\{ba3ca493-05fb-4188-a767-f40c03db2672}]
#="OLE CATIA.Application" "AppID"="{ba3ca493-05fb-4188-a767-f40c03db2672}"
[HKEY_CLASSES_ROOT\CLSID\{ba3ca493-05fb-4188-a767-f40c03db2672}\LocalServer32]
#="\"C:\\Program Files\\Dassault Systemes\\B18\\intel_a\\code\\bin\\CNEXT.exe\" -env \"CATIA_PLM_Express.V5R18.B18\" -direnv \"C:\\Documents and Settings\\All Users\\Application Data\\DassaultSystemes\\CATEnv\""
[HKEY_CLASSES_ROOT\CLSID\{ba3ca493-05fb-4188-a767-f40c03db2672}\ProgID]
#="CATIA.Application.v518"
[HKEY_CLASSES_ROOT\CLSID\{ba3ca493-05fb-4188-a767-f40c03db2672}\VersionIndependentProgID]
#="CATIA.Application"
I verified that the import worked, but when I run my application I come accross the following error when I try to connect to it.
System.Runtime.InteropServices.C OMException (0x80080005): Retrieving the COM class factory for component with CLSID {BA3CA493-05FB-4 188-A767-F40C03DB2672} failed due to the following error: 80080005 Server execution failed (Exceptio n from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
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)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
I'm able to run this program fine on the normal installs using "CATIA.Application" and "CATIA.Application.1", but here is the code I use to connect to the Application if it matters:
public CatiaApplication() {
Type catia_program_id = Type.GetTypeFromProgID( "CATIA.Application.v518" );
try {
this._instance = (Application)Activator.CreateInstance( catia_program_id );
}
catch( Exception ex ) {
throw new ApplicationException( "Failed to access Catia Application: " + ex.ToString());
}
}
Anybody have any ideas? I haven't tried to reboot the box but so far it looks like the changes take effect immediately.
Shouldn't it be this instead?
[HKEY_CLASSES_ROOT\CATIA.Application.v518]
"CLSID"="{ba3ca493-05fb-4188-a767-f40c03db2672}"
where you wrote it:
[HKEY_CLASSES_ROOT\CATIA.Application.v518\CLSID]
#="{ba3ca493-05fb-4188-a767-f40c03db2672}"

Categories

Resources