How to eliminate warning about ambiguity?

C#Visual Studio-2010WarningsCompiler WarningsOffice Interop

C# Problem Overview


I have this warning:

> Warning 3 Ambiguity between method 'Microsoft.Office.Interop.Word._Application.Quit(ref object, ref object, ref object)' and non-method 'Microsoft.Office.Interop.Word.ApplicationEvents4_Event.Quit'. Using method group.

on my line

wordApplication.Quit();

I have tried replacing it with:

wordApplication.Quit(false); // don't save changes

and

wordApplication.Quit(false, null, null); // no save, no format

but it keeps giving me this warning. It's not a huge problem because the code compiles perfectly and functions as expected, but I'd like to get rid of the warnings. What can I do?

C# Solutions


Solution 1 - C#

Explicitly cast the reference to the type _Application:

((_Application)wordApplication).Quit(); 

Solution 2 - C#

It's saying there are two quit methods in the included namespace you can if you like change quit to Microsoft.Office.Interop.Word._Application.Quit to remove the message or (haven't personally tried this) use a using statement.

Solution 3 - C#

I used this

   object oMissing = System.Reflection.Missing.Value;
   ((Microsoft.Office.Interop.Word._Application)wordApp).Quit(ref oMissing, ref oMissing, ref oMissing);
               wordApp = null;
               GC.Collect();
               GC.WaitForPendingFinalizers();

Solution 4 - C#

I believe you need to define the type of the parameters to Quit. I use the following, which seems to work.

using Microsoft.Office.Interop.Word;
...
Application wordApplication = new Application();
...
    object paramMissing = Type.Missing;
    object saveOptionsObject = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
        wordApplication.Quit(ref saveOptionsObject, ref paramMissing, ref paramMissing);
        wordApplication = null;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1002358View Question on Stackoverflow
Solution 1 - C#phoogView Answer on Stackoverflow
Solution 2 - C#smitecView Answer on Stackoverflow
Solution 3 - C#user3397383View Answer on Stackoverflow
Solution 4 - C#Kim CrosserView Answer on Stackoverflow