Visual Basic .NET "'[method]' is ambiguous across the inherited interfaces" error message when using Office Automation (315981)



The information in this article applies to:

  • Microsoft Excel 2002
  • Microsoft Excel 2000
  • Microsoft Outlook 2002
  • Microsoft Outlook 2000
  • Microsoft PowerPoint 2002
  • Microsoft PowerPoint 2000
  • Microsoft Word 2002
  • Microsoft Word 2000
  • Microsoft Visual Basic .NET (2002)

This article was previously published under Q315981

SYMPTOMS

When you use Visual Basic .NET to automate a Microsoft Office application, and an Automation object has both a method and an event with the same name, you may receive the following compile time error message when you build the project:
BC30685: '[Method]' is ambiguous across the inherited interfaces '[Interface1]' and '[Interface2]'.
For example, Word 2000 and Word 2002 expose both a Quit method and a Quit event on the Application object. If your code calls the Quit method, you receive the following compile error message:
'Quit' is ambiguous across the inherited interfaces 'Word._Application' and 'Word.ApplicationEvents3_Event'.

CAUSE

When you import a COM reference into your .NET project, Visual Basic .NET automatically generates a runtime callable wrapper (RCW) to wrap the component and expose it to the Common Language Runtime as a native .NET object. This object implements the default interface for the COM object, and exposes functionality for sinking the default events. If the object that is wrapped has both a method and an event with the same name, the default RCW sets up conflicting names, and Visual Basic .NET is unsure which interface member your code is attempting to access.

RESOLUTION

To resolve this problem, you can use one of the following methods:
  • Explicitly cast the object to the correct interface before you call the Quit method. For example, you can use the following:
    CType(oWordApp, Word._Application).Quit()
  • Change the variable declaration to use the extended Class wrapper object for the object. For example, instead of using Word.Application, change the declaration to resemble the following:
    Dim oWordApp As New Word.ApplicationClass()

STATUS

Microsoft is researching this problem and will post more information in this article when the information becomes available.

MORE INFORMATION

Office applications are not the only COM servers that may exhibit this problem when they are automated in Visual Basic .NET. The problem is not with the COM server or Visual Basic .NET itself, but with the RCW that the .NET Framework generates. By default, the type library importer for .NET does not resolve conflicting names.

The following Office Automation objects and methods may generate this compile error message if a standard RCW is generated for your Visual Basic .NET project:

Method Office Interface RCW Event Interface
NewWorkbook Excel._Application Excel.AppEvents_Event
Activate Excel._Workbook Excel.WorkbookEvents_Event
Activate Excel._Worksheet Excel.DocEvents_Event
Calculate Excel._Worksheet Excel.DocEvents_Event
Activate Excel._Chart Excel.ChartEvents_Event
Select Excel._Chart Excel.ChartEvents_Event
NewDocument Word._Application Word.ApplicationEvents3_Event
Quit Word._Application Word.ApplicationEvents3_Event
Close Word._Document Word.DocumentEvents_Event
NewPresentation PowerPoint._Application PowerPoint.EApplication_Event

Steps to Reproduce the Behavior

  1. Start Visual Studio .NET and create a new Visual Basic Windows Application project named WordQuitTest. Form1 is created by default.
  2. On the Project menu, click Add Reference. In the Reference dialog box, click the COM tab, double-click Microsoft Word 10.0 Object Library in the list, and then click OK to have Visual Basic .NET create a wrapper and add it to your project.
  3. Use the Toolbox to add a button to Form1, and then double-click the button to open the code window for Form1.
  4. Add the following to the top of Form1.vb:
    Imports Microsoft.Office.Interop
    					
  5. Paste the following code in the button click method in Form1.vb:
    Private Sub Button1_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgs) Handles Button1.Click
    
       Dim oWordApp As New Word.Application()
       oWordApp.Visible = True
       MsgBox("App Name = " & oWordApp.Name)
       oWordApp.Quit()
    
    End Sub
    					
  6. On the Build menu, click Build Solution to build the project. You receive a compile error message.

Modification Type:MinorLast Reviewed:8/12/2005
Keywords:kbvs2002sp1sweep kbAutomation kbbug kbpending KB315981