Click here to Skip to main content
15,891,687 members
Please Sign up or sign in to vote.
3.75/5 (4 votes)
See more:
The warning under the words:
Quit , Close in the last lines .

This is the warning:
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.



This is the code:

private void button1_Click_1(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.ApplicationClass();
            object nullobj = System.Reflection.Missing.Value;
            object file = @"C:\1.doc";

            Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(
            ref file, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj,
            ref nullobj, ref nullobj, ref nullobj, ref nullobj);
            doc.ActiveWindow.Selection.WholeStory();
            doc.ActiveWindow.Selection.Copy();
            IDataObject data = Clipboard.GetDataObject();
            string text = data.GetData(DataFormats.Text).ToString();
            MessageBox.Show(text);
            doc.Close(ref nullobj, ref nullobj, ref nullobj);
            app.Quit(ref nullobj, ref nullobj, ref nullobj);

            textBox1.Text = text;
        }
Posted
Updated 20-Aug-10 3:27am
v2
Comments
Toli Cuturicu 20-Aug-10 9:40am    
Reason for my vote of 1
no question
Nish Nishant 20-Aug-10 17:09pm    
Reason for my vote of 5
Not sure why that other guy 1-voted you. 5-ing your post to make up for the 1 vote.
Christian Graus 20-Aug-10 17:18pm    
Reason for my vote of 5
I agree with Nish, so I'm 5ing too.

In C# a method name cannot clash with an event name. MSIL permits this though. The COM wrapper that's been generated seems to have an event and a method both with the same name. The C# compiler can consume assemblies with name-clashes of this nature, but it will still throw a warning. In this case the warning is superficial and useless since you cannot invoke an event directly like that on a different object, so it's completely safe to ignore. You may be able to get around it by using some casting if the warning is that annoying to you.
 
Share this answer
 
The warning means what it says. Ambiguity means 'I can't work out which one of these to use'. It's says you're calling 'quit' and there's two 'quit' objects.
 
Share this answer
 
Thx Guys :) Got an answer :PPP
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900