Could not create excel instance.( System.Runtime.InteropServices.COMException (0x80080005))

milky007 6 Reputation points
2022-05-12T01:52:35.793+00:00

[Win10/Office2016/C#(WPF)]
I am making an Excel automation program using Microsoft.Office.Interop.Excel.
In general, it works normally, but intermittently a problem occurs when generating Excel.

The excel generat code is as follows.
Microsoft.Office.Interop.Excel.Application App = new Microsoft.Office.Interop.Excel.Application();

  1. Sometimes it takes time to generate Excel (generated after 2-3 seconds / But when there are no problems, it runs almost immediately.)
  2. After not responding for a long time, the following exception occurs.

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005.
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)

I've already tried reinstalling Office and checking the registry above, but it doesn't work.

  1. Why does it take so long to create Excel?
  2. Under what circumstances does the 0x80080005 exception usually occur?
  3. Is there any workaround?
Developer technologies | Windows Presentation Foundation
Developer technologies | C#
{count} vote

4 answers

Sort by: Most helpful
  1. 2022-05-24T17:15:38.707+00:00

    There are a handful of free third party libraries out there.

    1 person found this answer helpful.

  2. 2022-05-24T17:48:21.233+00:00

    There are a few free third-party libraries.

    1 person found this answer helpful.
    0 comments No comments

  3. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-05-25T18:58:50.7+00:00

    Take a look at EPPlus to read a sheet into a DataTable, convert to a pivot table then import the pivot table into a new sheet followed by removing the original.

    Here are starter methods excluding pivot table where there is a article here.

    Edit Pivot tables in EPPlus

    1 person found this answer helpful.

  4. Mounira Ben Ali 1 Reputation point
    2022-06-07T06:29:54.223+00:00

    Ok good luck

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.