19

Anyone know how to solve this warning message?

Ambiguity between method 'Microsoft.Office.Interop.Word._Document.Close(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.DocumentEvents2_Event.Close'. Using method group.

Pooven
  • 1,744
  • 1
  • 25
  • 44
Su Beng Keong
  • 1,034
  • 1
  • 13
  • 30

2 Answers2

30

The only way I've managed to resolve the warning is to use an explicit cast:

var doc_close = (Microsoft.Office.Interop.Word._Document) _doc;
doc_close.Close();    

If you already have a using for Microsoft.Office.Interop.Word you can simplify the cast to:

var doc_close = (_Document) _doc;
doc_close.Close();   

or even just

((_Document)_doc).Close();
Pooven
  • 1,744
  • 1
  • 25
  • 44
Tod
  • 8,192
  • 5
  • 52
  • 93
0

In more recent versions of visual studio, you can add this line to the top of the source file to remove the ambiguity.

using Document = Microsoft.Office.Interop.Word.Document;
Nicholas Hunter
  • 1,791
  • 1
  • 11
  • 14