Click here to Skip to main content
15,617,358 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed a console application to create OUTLOOK meeting requests. It is perfectly working fine when Im running it in Visual Studio. But when I schedule it in the Task Scheduler, it does not work. It gives me the bellow error.

Error : Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))

below is my code.

public MeetingDVO sendOneTimeMeeting(MeetingDVO dvo)
       log.Info("In side Send Onetime Meeting");
       object outlookObject = null;
       Outlook.Application oApp = null;
       Outlook.AppointmentItem agendaMeeting = null;
       Account acc = null;
       string status = string.Empty;
           outlookObject = Marshal.GetActiveObject("Outlook.Application");

           if (outlookObject != null)
               log.Info("Marshal Object Created");
               oApp = new Outlook.Application();
               oApp = new Microsoft.Office.Interop.Outlook.Application();

           if (true)
               log.Info("creating outlook Object");
               //oApp = new Outlook.Application();
               //oApp = CreateOrAttachToOutlookApplication();
               log.Info("Object created");
               agendaMeeting = (Outlook.AppointmentItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
               log.Info(" agendaMeeting Object created");
               acc = SetAccount(oApp);
               log.Info(" Account created");
               if (agendaMeeting != null)
                   log.Info(" in side Account IF");
                   Outlook.NameSpace nameSpace = oApp.GetNamespace("MAPI");
                   log.Info(" Namespace");
                   agendaMeeting.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
                   agendaMeeting.Location = dvo.Location;
                   agendaMeeting.Subject = dvo.Subject;
                   agendaMeeting.Body = dvo.Body;
                   agendaMeeting.Start = dvo.TimeSlot;
                   agendaMeeting.Duration = dvo.Duration;
                   //agendaMeeting.RequiredAttendees = ";";
                   agendaMeeting.RequiredAttendees = "";
                   //agendaMeeting.RequiredAttendees = "";
                   //agendaMeeting.ForceUpdateToAllAttendees = true;
                   //agendaMeeting.ResponseRequested = true;
                   ((Outlook._AppointmentItem)agendaMeeting).SendUsingAccount = acc;
                   dvo.EntryID = agendaMeeting.EntryID;
                   dvo.Remarks = MeetingSucess;

                   dvo.Remarks = MeetingError + " : " + "Meeting Object is Null";
       catch (System.Exception ex)
           log.Info(ex.InnerException +":::::: MESSAGE----"+ex.Message);
           dvo.Remarks = MeetingError + " : " + ex.Message;
           oApp = null;
           agendaMeeting = null;
           acc = null;

       return dvo;

any suggestions?
ZurdoDev 15-Jul-14 11:52am    
Sounds like a permissions issue. I would look in the event viewer more.
Kasun Koswattha 15-Jul-14 13:40pm    
I tried changing the permissions. but didnt work. But when i double click the exe it runs perfectly.
Dave Kreskowiak 15-Jul-14 12:42pm    
What account is the Task scheduled to run under?
Kasun Koswattha 15-Jul-14 13:41pm    
My Domain account. the account which i use to login to my computer, I have local admin privileges also.

1 solution

Well, I can tell you that the error message, combined with your code:
outlookObject = Marshal.GetActiveObject("Outlook.Application");

means that Outlook doesn't appear to be running at the time the call is made.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900