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



Answer this question

Compiler Warning CS0467

  • D3lta

    One is a method, whereas the other is an event.

  • Robert Nguyen

    > 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


  • rfinlay

    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

  • Vhii

    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.


  • nojetlag

    Thanks this helped me a lot.

  • Compiler Warning CS0467