Outlook 2003 Object Model using Visual C# 2005 Express IDE Beta1

G

Guest

Following an intro article from the msdn homepage about using C# to access
the Outlook 2003 Object Model in Applications and Add-Ins, I came across a
problem with the OPine example.

I was reading through the article on the C# msdn home page about introducing
the Outlook 2003 Object Model through C#.

I carefully programmed the OPine example, but after ironing out reference
errors and syntax, etc., I finally had this one annoying error. I can see
obviously what is causing it (two methods with similar names is my guess),
but for the life of me can't figure out how to fix it! The code is EXACTLY as
out of the article...

Error:
Error 1 Ambiguity between
'Microsoft.Office.Interop.Outlook._MailItem.Send()' and
'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Send'
C:\Documents and Settings\rclements\Local Settings\Application
Data\Temporary Projects\OPine\Program.cs 122 19

Here is the code reference:
public static void SendNewMail(ApplicationClass o)
{
// Create a new MailItem.
MailItem myMail =
(MailItem)o.CreateItem(OlItemType.olMailItem);
// Now gather input from user.
Console.Write("Receiver Name: ");
myMail.Recipients.Add(Console.ReadLine());
Console.Write("Subject: ");
myMail.Subject = Console.ReadLine();
Console.Write("Message Body: ");
myMail.Body = Console.ReadLine();
// Send it!
myMail.Send();
}

It is the method Send() in the last line of the static method which causes
the error...

Can anyone help me compile this? How can I force it to choose the correct
option?

Will
 
G

Guest

Brilliant Willy, thanks!

If you have time, any chance you could explain why this happens? And if I
should look out for similar problems? I ask becaus ethe examples were for
VS.NET 2003, which I have, but was trying out the Beta Express version. Is it
likely a bug, maybe?

I would assume that as the article was written for 2003, then likely this
problem doesn't happen, you see, as I would be surprised if the code was not
tested before publication (well, maybe "surprised" isn't the right word...
maybe irked is better!).

Will
 
W

Willy Denoyette [MVP]

WillShakespeare said:
Brilliant Willy, thanks!

If you have time, any chance you could explain why this happens? And if I
should look out for similar problems? I ask becaus ethe examples were for
VS.NET 2003, which I have, but was trying out the Beta Express version. Is
it
likely a bug, maybe?

I would assume that as the article was written for 2003, then likely this
problem doesn't happen, you see, as I would be surprised if the code was
not
tested before publication (well, maybe "surprised" isn't the right word...
maybe irked is better!).

Will

I don't think it's a bug, apparently the C# compiler team decided to flag an
error when he encounters an object that has an event and a method with the
same name, something they silently resolved in v1.x. You can get around this
issue by an explicit cast to the correct interface (or by using vb.net ;-),
like this:

(myMail as Outlook._MailItem).Send();
or
( (Outlook._MailItem)myMail ).Send();

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top