Creating Excel file in Console Application - c#

I have a C# console application and it is creating excel file and send mail to our customer.
It's working in test server but its not working in production server and we get this following error ;
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
I did not find any solution for this error.
We're creating excel file like this and this code fire an error ;
_appExcel = new Microsoft.Office.Interop.Excel.Application();
Anyone help me about this situation ? Thanks !

Related

Retrieving the COM class factory for component with CLSID failed due to the following error: 80040154 Class not registered

I have a web application which is used to send email. In this application, I am reading data from an Excel file and send email.
This is working fine in the local system, but not working after uploading on the server.
I have received the following errors
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)).
How can I fix it?
Solution: to this badimageformatexception is setting the 'Enable32bitApplications' to 'True' in IIS Apppool properties for the right apppool.

Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 80070005 Access is denied

I'm using https://www.npmjs.com/package/node-msoffice-pdf to convert a word to a pdf. This solution works perfectly on my computer.
I updated my app in IIS and I get this error when calling the web service that converts the docx to pdf:
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
I have tried several answers and tutorials step by step such as:
Accessing Office Word object model through asp.net results in "failed due to the following error: 80070005 Access is denied."
Retrieving the COM class factory for component with CLSID failed due to the following error: 80070005 Access is denied
https://jayeshsidhwani.wordpress.com/tag/hresult-0x80070005-e_accessdenied/
https://waheedrous.wordpress.com/2014/01/26/error-office-interop-assemblies
But I got to nowhere.
I also tried to run my app in the server but as localhost and it worked perfectly, zero problems.
I noticed that the CLSID in the error message it isn't the same as the Microsoft Word 97 - 2003 Document Component Service App ID.
The only tutorial that got me somewhere is this one http://toastergremlin.com/?p=543. The error was gone but the Word wasn't being opened and the web service just got stuck.
In the Microsoft Word 97 - 2003 Document Component Service I tried to add the following users: NETWORK_SERVICE, IIS_IUSRS, PC\Users and the apppool associated with my website.
I had similar issue when trying to create my own Interop DLL thru IIS web. And after lot of searches, this post solved my life

Error E_ACCESSDENIED in C# Microsoft.Office.Interop.Excel()

I have created a windows service that repetitively updates the same excel file. While running the Windows Service, I am receiving the following Error:
Error Message Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
This error is thrown at the following line of code:
ExcelApp = new Microsoft.Office.Interop.Excel.Application();
Is there a work-around for this ?
I followed the steps mentioned in the following SO link but that didn't helped me overcome these error. I tried solution from few other questions as well and none of them worked for me.

WCF Service Access Denied for Microsoft office introp word Application

I was working on file conversion of doc to docx in my using WCF service that are hosted on IIS. When I was trying to create an object for
var app = new Microsoft.Office.Interop.Word.Application();
I got this error
Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
I also did DCOM Config that I found solution from other posts but still I have same problem.

COM class factory 80040154 server error

I wasn't getting this error before on localhost, but now it's occurring when I uploaded my ASP.NET C# web app to the server. I've been looking for an answer how to fix this, but cannot seem to get rid of it. I have a Microsoft.Office.Interop.Excel DLL which I am trying to use to export data from a dataset to excel. I was told by customer service that the domain that I have registered is hosted on a 32-bit server. Please help!
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
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.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154.
Source Error:
Line 499: object misValue = System.Reflection.Missing.Value;
Line 500:
Line 501: xlApp = new Excel.ApplicationClass();
Line 502: xlWorkBook = xlApp.Workbooks.Add(misValue);
Line 503: xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
Look at http://support.microsoft.com/kb/897646
Article ID: 897646 - Last Review: January 5, 2006 - Revision: 1.10
Office 2003 Update: Redistributable Primary Interop Assemblies is available for download
Step 1.- Install Office 2003
Step 2.- Install SP Office
Step 3.- Install O2003PIA components
There a guy describing step by step how to solve you problem here
If the other solution doesn't work try adding the following to the web.config after
<identity impersonate="true" userName="******" password="*******"/>
Replacing the * with a valid Windows username and password that would have access to Excel.
Make sure you login as the identity you are impersonating so you can verify that it has access to Excel (Office 2010 tends to want to reactivate Office for each user I've noticed).

Categories