C# Programming with EXTRA! and INFOConnect COM Automation Interfaces

  • 7021282
  • 13-Jun-2013
  • 02-Mar-2018


EXTRA! X-treme version 9.2 or higher
INFOConnect version 9.1 or higher


When programming in C# using the EXTRA! or INFOConnect COM automation interface, several wait methods require extra consideration. This technical note lists the methods and describes the factors to consider.

Wait Methods

The following wait methods require extra consideration when programming in C# using the EXTRA! or INFOConnect COM automation interface:


These methods all have a return type such as _ScreenWait or _FileWait. These simple objects, which are based on IDISPATCH, are declared with the dispinterface statement as indicated by the COM .idl definitions generated by the EXTRA! type library (extra.tlb) or INFOConnect type library (AccMgr.tlb). As such, they have no corresponding coclass to define them as a particular named type. And because coclasses are not available in the definitions, a necessary cast will fail at runtime.

Error Examples

This code example compiles, but at runtime returns an error.

EXTRA._ScreenWait waitobject = (EXTRA._ScreenWait) myScreenObj.WaitForString(...);

Error: "Unable to cast COM object of type 'System.__ComObject' to interface type 'EXTRA._ScreenWait'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{0571B7A0-F9B1-11CF-884D-08005AC0F29E}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))".

This code example will not compile, and instead returns an error. (To make the code compile, you must make that cast in C#.)

EXTRA._ScreenWait waitobject = (EXTRA._ScreenWait) myScreenObj.WaitForString(...);

Error: " Cannot implicitly convert type 'object' to 'EXTRA._ScreenWait'. An explicit conversion exists (are you missing a cast?)"

This last code example compiles, but does not provide access to the necessary methods on the returned object.

EXTRA._ScreenWait waitobject = myScreenObj.WaitForString(...);

In C#, you can only call a method on the returned object that is explicitly defined on it. For example,

Object waitobject = myScreenObj.WaitForString(...);


To resolve this problem, use one of the following two options:

Option 1 (Recommended)

Use VB.Net to write portions of your application that involve EXTRA!. VB.Net allows you to call a method using an "Object" variable even though the method is not explicitly defined as a member of "Object". In Visual Studio, you can add a secondary project written in VB.Net to your C# project, and invoke methods employing EXTRA! through it.

The following example illustrates how to use WaitForString to create a simple console application in VB.Net:

Module Module1
Sub Main()
Dim sys As New EXTRA.ExtraSystem
Dim sess As EXTRA.ExtraSession = sys.ActiveSession
Dim scr As EXTRA.ExtraScreen = sess.Screen 

'wait 10 seconds for "xx"
Dim waitobject As Object = scr.WaitForString("xx")
Dim rc As Boolean = waitobject.Wait(10000)
If rc Then
Console.WriteLine("Found the string before timeout expired.")
Console.WriteLine("Timeout occurred waiting for the string.")
End If

End Sub
End Module

Option 2

Use C# to write your own versions of "WaitForString" or "WaitHostQuiet" using other methods provided by EXTRA (such as GetString) and set up a timer loop. Code samples are available from KB 7021278, “EXTRA! Developer Tools: API Code Samples and Manuals.”

Additional Information

Legacy KB ID

This document was originally published as Attachmate Technical Note 2673.