Compiler Warning CS0467

In the following, I get a compiler warning (with VS2005 Beta 2, but not VS2003) on the Close() call. I'm using a reference to Microsoft Word 9.0 Object Library.


Word.ApplicationClass WordApp =new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
Word.
Document aDoc = WordApp.Documents.Add(ref missing,ref missing,ref missing,ref missing);
aDoc.Close(
ref missing,ref missing,ref missing);
WordApp.Quit(
ref missing,ref missing,ref missing);

The warning is: Warning 1 Ambiguity between method 'Word._Document.Close(ref object, ref object, ref object)' and non-method 'Word.DocumentEvents_Event.Close'. Using method group.

The two Close candidates look pretty different to me ... what is the problem and how can I resolve this?

Cheers, RL

[2347 byte] By [RogerLainson] at [2008-2-16]
# 1
Try this, I used word 11. to complie it

Word.ApplicationClass WordApp = new Word.ApplicationClass();
object missing = System.Reflection.Missing
.Value;
Word.
Document aDoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref
missing);
((Word._Document)aDoc).Close(
ref missing, ref missing, ref
missing);
WordApp.Quit(
ref missing, ref missing, ref missing);

or

Word.ApplicationClass WordApp = new Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
Word.
Document aDoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
#pragma warning disable 0467
aDoc.Close(
ref missing, ref missing, ref missing);
#pragma warning restore 0467
WordApp.Quit(
ref missing, ref missing, ref missing);
bet the 1st one is better.

erymuzuan at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
Thanks - the first snippet successfully avoids the warning.

Now I look more carefully, I see Word.Document is an interface, and has multiple base types, namely _Document and DocumentEvents_Event interfaces. But I'm still puzzled as to why the Close() method of one and Close event of the other are (suddenly) not distinguishable by their signature. Does overloading work differently with interfaces, or this a VS2005 bug?

Cheers, RL

RogerLainson at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3
One is a method, whereas the other is an event.
DavidM.Kean at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4

> One is a method, whereas the other is an event.
Sure, but this doesn't answer the question, why are the Close() method of one interface and Close event of the other not distinguishable by their signature? Is this a compiler bug: surely only the method is usable in this context?

JocularJoe at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 5
Thanks this helped me a lot.
mcm_ham at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...