Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning CS0467 when using 'Microsoft.Office.Interop.Word._Document.Close'

The problem (C# compiler warning message):

warning CS0467: 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.

The (partial..) solution: Compile time warning when using 'Microsoft.Office.Interop.Word._Document.Close'

The dilemma: If I explicitly cast to Microsoft.Office.Interop.Word._Document, ReSharper warns me that the "Type cast is redundant"

The question: Is there a real solution for this warning message, not just patchwork?


1 Answers

Just don't cast, C# doesn't require it:

Word._Application app = new Word.Application();
Word._Document doc = app.Documents.Add(...);
doc.Close(...);    // No ambiguity
app.Quit(...);
like image 162
Hans Passant Avatar answered Jul 25 '26 05:07

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!