Office 365 Library Issue

jassi123

New member
Joined
Oct 29, 2019
Messages
2
Programming Experience
1-3
Hello Team,

I have created a function to read email from outlook. Here is my code:-

C#:
using System;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Office.Interop.Outlook;
using Microsoft.Office365.OutlookServices;
namespace EmailTrigger
{
    class Program
    {
        static void Main(string[] args)
        {
            ReadMailItems();
        }
        private static void ReadMailItems()
        {
            Application outlookApplication = null;
            NameSpace outlookNamespace = null;
            MAPIFolder inboxFolder = null;
            Items mailItems = null;
            try
            {
                outlookApplication = new Application();
                outlookNamespace = outlookApplication.GetNamespace("MAPI");
                inboxFolder = outlookNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                mailItems = inboxFolder.Items;
                foreach (MailItem item in mailItems)
                {
                    var stringBuilder = new StringBuilder();
                    stringBuilder.AppendLine("From: " + item.SenderEmailAddress);
                    stringBuilder.AppendLine("To: " + item.To);
                    stringBuilder.AppendLine("CC: " + item.CC);
                    stringBuilder.AppendLine("");
                    stringBuilder.AppendLine("Subject: " + item.Subject);
                    stringBuilder.AppendLine(item.Body);
                    Console.WriteLine(stringBuilder);
                    Marshal.ReleaseComObject(item);
                }
            }
            catch (System.Exception ex) { throw ex; }
            finally
            {
                ReleaseComObject(mailItems);
                ReleaseComObject(inboxFolder);
                ReleaseComObject(outlookNamespace);
                ReleaseComObject(outlookApplication);
            }

        }
        private static void ReleaseComObject(object obj)
        {
            if (obj != null)
            {
                Marshal.ReleaseComObject(obj);
                obj = null;
            }
        }
    }
}
However I am getting the following error message when I execute this code:-

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.
File name: 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
at EmailTrigger.Program.ReadMailItems()
at EmailTrigger.Program.Main(String[] args) in C:\Users\jaspreet1.singh\source\repos\EmailTrigger\EmailTrigger\Program.cs:line 12

Can someone please look into this issue.

Regards,
(Jaspreet Singh)
 
Last edited by a moderator:

Skydiver

Well-known member
Joined
Apr 6, 2019
Messages
646
Location
Virginia Beach, VA
Programming Experience
10+
The error is pretty self-explanatory. The runtime couldn't load the assembly. Assuming that the assembly exists, and it is in the search path, then this commonly to happen if you are mixing bitness (e.g. 32-bit trying to load 64-bit, or 64-bit trying to load 32-bit.) So the questions are:
Does the assembly exist?
Is the assembly in the search path (or the GAC)?
Does the assembly CPU model match your program's CPU model?
 

jassi123

New member
Joined
Oct 29, 2019
Messages
2
Programming Experience
1-3
This assembly exists in in the project folder but doesn't exists in C:\windows\assembly folder.

Can you please help me out in this.....as I am stuck in mid of a project.
 
Top Bottom