How to eliminate warning about ambiguity?

我怕爱的太早我们不能终老 提交于 2019-11-27 22:38:46

Explicitly cast the reference to the type _Application:

((_Application)wordApplication).Quit(); 

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.

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();

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!