80040154 Class not registered ERROR in Outlook 201

2019-07-07 06:14发布

问题:

I am using Visual Studio 2010 to create a Outlook 2010 Add In. I try to create a new Outlook AppointmentItem to work with thinking that I can add it to the calendar eventually.

Microsoft.Office.Interop.Outlook.AppointmentItem tempApp = new Microsoft.Office.Interop.Outlook.AppointmentItem();

But when the AddIn runs and trys to create the AppointmentItem object, I get this error on the line above.

System.Runtime.InteropServices.COMException was unhandled by user code
      Message=Retrieving the COM class factory for component with CLSID {00061030-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
      Source=mscorlib
      ErrorCode=-2147221164

What can I do to "register the class"? I'm guessing it has to do with Microsoft.Office.Interop.Outlook.dll in some way.

回答1:

The exception message is not very helpful, they could have done a better job with the COM declaration. This is by design, the class is not registered. You must create an instance of it with the Application.CreateItem() method.



回答2:

Do you have Outlook 2010 installed? The interop assembly is just a .NET wrapper for COM component of Outlook 2010. This component should be registered for interop to work. This registration is usually performed by the application owning the component i.e. Outlook in this case.

You could try registering the component by regsvr32 utility, but you must know the name of the dll containing the component.

Use OleView (now called "OLE-COM object viewer") from "Start Menu\Programs\MS Visual Studio xxxx\Microsoft Windows SDK Tools" to see registered components.

And check for x86/x64 option. E.g. you may have 32-bit version of this component registered and 64-bit application or vice versa.

http://www.msoutlook.info/question/461



回答3:

Here is what I normally do for all the Outlook Interop Objects I need:

    // In Global Properties
    public static Outlook.Application olook = new Outlook.Application();        // Outlook Application Object.

    // In Method 
    Outlook.AppointmentItem olookAppointment = (Outlook.AppointmentItem)olook.CreateItem(Outlook.OlItemType.olAppointmentItem);

It is similar to the above solution.