Microsoft KB Archive/315981

= Visual Basic .NET &quot;'[method]' is ambiguous across the inherited interfaces&quot; error message when using Office Automation =

Article ID: 315981

Article Last Modified on 1/30/2007

-

APPLIES TO


 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition
 * Microsoft Outlook 2002 Standard Edition
 * Microsoft Outlook 2000 Standard Edition
 * Microsoft PowerPoint 2002 Standard Edition
 * Microsoft PowerPoint 2000 Standard Edition
 * Microsoft Word 2002 Standard Edition
 * Microsoft Word 2000 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-



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:

Steps to Reproduce the Behavior
 Start Visual Studio .NET and create a new Visual Basic Windows Application project named WordQuitTest. Form1 is created by default. 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.</li> Use the Toolbox to add a button to Form1, and then double-click the button to open the code window for Form1.</li>  Add the following to the top of Form1.vb: Imports Microsoft.Office.Interop </li>  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(&quot;App Name = &quot; & oWordApp.Name) oWordApp.Quit

End Sub </li> On the Build menu, click Build Solution to build the project. You receive a compile error message.</li></ol>

Keywords: kbvs2002sp1sweep kbautomation kbbug kbpending KB315981

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.