Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook Object Model

Status
Not open for further replies.
Feb 4, 2002
792
GB
Hi All,

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, but for the life of me can't figure out how to fix it!

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
 
Never mind. I used MailItemClass instead of MailItem when creating my MailItem. This seems to have done the trick.

Still would like to know why it gets confused, though...

Will
 
Damn... although it would compile, using MailItemClass didn't work when I ran the program... so still don't know what to do... can anyone help?

Will
 
When you get an ambiguous reference, it means that the compiler can't tell the difference between two types that are in different namespaces.

So if you have a "Triangle" class in both MyCorp.Graphlib.Primitives and MyCorp.BizGraph.Shapes, the compiler gets confused when you just declare a variable of type Triangle:
Code:
using MyCorp.Graphlib.Primitives;
using MyCorp.BizGraph.Shapes;
:
Triangle myTriangle = new Triangle();
The answer is either put an alias on one of the using statements:
Code:
using Prims = MyCorp.Graphlib.Primitives;
using MyCorp.BizGraph.Shapes;
:
Prims.Triangle myTriangle = new Prims.Triangle();
Or fully qualify one of them by removing one of the usings:
Code:
using MyCorp.BizGraph.Shapes;
:
MyCorp.Graphlib.Primitives.Triangle myTriangle = new MyCorp.Graphlib.Primitives.Triangle();
Chip H.

____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks chip... I tried the alias thing first off, but this didn't work. However, I found a solution (finally!):

(myMail as _MailItem).Send();

Using the as keyword to specify which. Didn't know this could be done before now! So you live and learn! :)

Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top