By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,152 Members | 2,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,152 IT Pros & Developers. It's quick & easy.

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

P: n/a
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_Ev ent.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
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
(myMail as Outlook._MailItem).Send();

Willy.

"WillShakespeare" <Wi*************@discussions.microsoft.com> wrote in
message news:CC**********************************@microsof t.com...
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_Ev ent.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

Nov 16 '05 #2

P: n/a
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

"Willy Denoyette [MVP]" wrote:
(myMail as Outlook._MailItem).Send();

Willy.

"WillShakespeare" <Wi*************@discussions.microsoft.com> wrote in
message news:CC**********************************@microsof t.com...
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_Ev ent.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


Nov 16 '05 #3

P: n/a

"WillShakespeare" <Wi*************@discussions.microsoft.com> wrote in
message news:94**********************************@microsof t.com...
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.
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.