1
votes

I was trying to retrieve my outlook contacts in c#.net Application. But While creating an object of outlook application, I am getting the error

 "AnswerWizard = '((Microsoft.Office.Interop.Outlook.ApplicationClass.(outlookObj)).AnswerWizard' threw an exception of type 'System.Runtime.InteropServices.COMException'"

I tried to register the dll using revsvr32 "DLL Path", but I am getting the error of Module loaded but DLLRegisterServer not found.

This is the code that I have written :

        DataSet ds = new DataSet();
        ds.Tables.Add("Contacts");
        ds.Tables[0].Columns.Add("Email ID");
        ds.Tables[0].Columns.Add("FirstName");
        ds.Tables[0].Columns.Add("LastName");

        Microsoft.Office.Interop.Outlook.Items OutlookItems;
        Microsoft.Office.Interop.Outlook.Application outlookObj;
        MAPIFolder Folder_Contacts;

        outlookObj = new Microsoft.Office.Interop.Outlook.Application();
        Folder_Contacts =(MAPIFolder)outlookObj.Session.GetDefaultFolder  (OlDefaultFolders.olFolderContacts);
        OutlookItems = Folder_Contacts.Items;

        for (int i = 0; i < OutlookItems.Count; i++)
        {
            Microsoft.Office.Interop.Outlook.ContactItem contact =(Microsoft.Office.Interop.Outlook.ContactItem)OutlookItems[i + 1];
            DataRow dr = ds.Tables[0].NewRow();
            dr[0] = contact.Email1Address;
            dr[1] = contact.FirstName;
            dr[2] = contact.LastName;

            ds.Tables[0].Rows.Add(dr);
            if (i == 10)
                break;
        }
        dgvContacts.DataSource = ds.Tables[0];
        return ds;

And I am getting the count as zero.

1
This is a very general exception, you should post the code that it's getting thrown from - Ben Aaronson

1 Answers

0
votes

I don't think Application.AnswerWizard ever worked in Outlook. What are you trying to do?