COM Exception 80040154 When creating an Excel Application - c#

I'm trying to run my application on a server which does not and will not have Office installed on it.
using EXCEL = Microsoft.Office.Interop.Excel;
...
EXCEL.Application app = new EXCEL.Application();//Exception thrown here
The code is working fine on my own system, but on the server it gives the following exception:
Unhandled Exception: System.Runtime.InteropServices.COMException:
Retrieving the COM class factory for component with CLSID {...} failed
due to the following error: 80040154 Class not registered
(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
both systems are 32bits, and I've copied the excel Interop dll next to application's exe. I've also installed O2010PIA.
any lead?

The Office Interop assemblies are runtime-callable wrappers (RCW) that allow you to interoperate with a copy of Office that's installed on the system via the COM API that it exposes.
The error message indicates that Excel isn't installed, exactly what I'd expect. You can't use the Interop assemblies on a machine without Office.

I'm trying to run my application on a server which does not and will
not have Office installed on it.
As Joe said, you'll need to install Excel for Interop to work. If you're dead-set against that, consider third-party alternatives. In general, Microsoft did not recommend installing Office on your server and using it with Interop - that being said, it will work (at least most of the time).

Related

Error when initializing Microsoft Excel interop (64-bit)

I have a website using asp.net with Excel 2010 Interop 64-bit (Microsoft.Office.Interop.Excel.dll).
I deployed code to the Windows Server 64 bit.
By using command:
xelApp = new Microsoft.Office.Interop.Excel.Application();
I see there is no error on this own server.
But from the other computer (same domain), sometimes (not always), I got the error:
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.
How could I fix this issue?
By install the Office 2010 64-bit to server 64-bit, I cannot see the Excel in DCOM config.
Please advise.
Thanks.
Check the folowing:
Is Microsoft Office Installed on the server? If not, you may install the MS Office and this feature should be working.
If you do not want to install the MS Office, you can use a similar tool, which is ClosedXML - 1 https://closedxml.codeplex.com/
I recommend to replace the Interop Excel with the ClosedXML.
That error code occurs due to security issues like insufficient privelage or due to incorrect username, password.

Running an ASP.NET application that uses Excel on a Windows Server

I have developped an asp.net application using microsoft office interop excel on my local machine, everything worked well, an excel file was build.
When I deploy the application on my server and run it, I am getting the following exception :
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))
I have done some research on forums, I know that it's probably because excel is missing on the server, however I am not able to find an appropriate solution, knowing that install excel on the server is not really possible. And also knowing that I would like to keep interop as my library.
Does anyone have a solution?
First, what ever you are trying to do, try to do it without using Excel (or any Office) interop in ASP.NET. Microsoft strongly discourages it, as it might not work as you expect.
There are plenty possibilities to do this without the 'client application' Excel, for example EPPlus.
Second, the problem with your code is the lack of Office installed or the wrong version of Office (also consider 32- or 64-bit platform versions).

Excel Interop - Type not registered

I have an C# winform app compiled for x86 platform, using excel 2003 COM interop libraries. The Visual studio project references the following interop files for office 2003)
Microsoft.Office.Interop.Excel.dll (v 11.0.0, specific version = true)
Microsoft.Vbe.Interop.dll (v 11.0.0, specific version = false)
This application runs fine on most computers with excel 2003,2007 and 2010, but one of the users reported the exception below to me.
This users has windows 7 and Office 2010
System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
at Microsoft.Office.Interop.Excel.ApplicationClass.get_Workbooks()
From what I've read, this problem can occurs with conflicting versions of Office, but as I'm specifically referencing the 2003 Office PIAs and distributing them alongside the application, I'm unsure of what can cause the problem.
Thanks
The user's registry is broken. He has Office installed or you would have never been able to get the Aplication object created but it is missing an entry in the Typelib registry key. It is required to allow the interop call to succeed.
Reinstalling Office is the sane and simple solution. This kind of lossage is rarely isolated.

Error in create access database?

I have a web application that create an access database. When I want to create this database, I add Microsoft.Office.Interpob.access.dao.dll from COM references.
This application work in my pc very well. But when I put this application in the customer server I get this error:
Retrieving the COM class factory for component with CLSID {CD7791B9-43FD-42C5-AE42-8DD2811F0419} failed due to the following error: 80040154
Note that the Microsoft Office Access is not install in customer server. Must I Install this program on this server or can I add some dll to resolve this problem or I have to do anything else?
Thanks.
Check out these links, they might help:
social.msdn.microsoft.com - "Error 80040154 retreiving COM Class factory"
asp.net - "Retrieving COM class factory failed due to the following error: 80040154"
software602.com - "KB987: Error code 80040154. Class not registered"
I know this is a little late for the the original poster, but hopefully this will be useful to others. The correct answer is:
No, you don't need to install Microsoft Office Access on the server.
But, you do need to install the Microsoft Office Access Runtime on the server. From my limited experience it doesn't seem to matter which office runtime - I had the 2013 runtime installed locally but when I installed the runtime on my server it was fine with the 2016 runtime (so both installed the required COM object). In my case I was installing the x64 version.
The Microsoft Office Access Runtime is free from Microsoft.
The Microsoft Access 2013 Runtime can be downloaded from: https://www.microsoft.com/en-gb/download/details.aspx?id=39358
The Microsoft Access 2016 Runtime can be downloaded from https://www.microsoft.com/en-gb/download/details.aspx?id=50040

Creating xlsx file from asp.net code

Hi i am using c# code for creating xlsx file. i have added the reference to my bin for Microsoft.Office.Interop.Excel Version 12.0.0.0
It Works ok on my local machine. But when i upload it to the server it throws the error in the page where i am creating the xlsx file
"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)).
"
can anybody plz help
You are getting the error because excel isn't installed on the server.
You shouldn't be automating Office in ASP.NET. It can lead to myriad performance and scale issues on your server. Office itself is designed for interactive desktop usage, not unattended execution in a non-GUI app. Here is the authoritative reference from MS on the matter:
http://support.microsoft.com/kb/257757
With that being said, there are third-party libraries designed specifically for manipulation of Excel in ASP.NET. OfficeWriter is one example:
http://www.officewriter.com

Categories

Resources