MissingMemberException error thrown when using EXTRACOM "late bound" VB.NET syntax

  • 7022945
  • 10-May-2018
  • 26-Oct-2020

Environment

Reflection Desktop (including Pro, for X, for IBM, or for UNIX and OpenVMS) 16.0 and higher
Reflection 2014
Reflection Pro 2014
Reflection for IBM 2014
Reflection for UNIX and OpenVMS 2014
Reflection for IBM 2011
Reflection for UNIX and OpenVMS 2011
Reflection Standard Suite 2011

Situation

A MissingMemberException error is thrown when using EXTRACOM "late bound" Visual Basic .NET (VB.NET) syntax with Reflection Desktop, Reflection 2014, or Reflection 2011.  This error occurs when working with the Reflection EXTRACOM API using VB.NET "late binding" syntax, (i.e., declaring variables "As Object") so that VB.Net will look them up at runtime.  Instantiating the EXTRACOM "System" object using the VB.NET "CreateObject" function succeeds, but any attempt to use methods or properties supplied by the System object will cause an exception in Visual Studio 2010 or 2012, as follows:

System.MissingMemberException was unhandled
HResult=-2146233070
Message=Public member 'ActiveSession' on type 'MarshalByRefObject' not found.
Source=Microsoft.VisualBasic
StackTrace:
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, Boolean ReportErrors)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at EXTRALateBinding.Module1.Main() in c:\users\nedge\documents\visual studio 2010\Projects\EXTRALateBinding\EXTRALateBinding\Module1.vb:line 8
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

This exception error does not occur when using the EXTRACOM in VBScript (.vbs file).  This exception error also does not occur when using Excel VBA.

Resolution

Workaround:
Use "Early Binding" VB.NET syntax instead, by adding a reference to EXTRACOM.dll (not the typelib) and using proper names for variable types:

    Dim sys As EXTRACOM.ExtraSystem
    Dim sess As EXTRACOM.ExtraSession
    sys = CreateObject("extra.system")
    sess = sys.ActiveSession
    sess.Screen.SendKeys("it works!")

This workaround can be used with VB.NET from Visual Studio 2012.  With VB.NET from Visual Studio 2010, it appeared that a reference can be added to EXTRACOM.dll, but Visual Studio was for some reason unable to hook things up correctly, because the reference to EXTRACOM never will show up in the project properties-references list


Resolution:
Upgrade to Reflection Desktop 16.1 SP1 U1 HF3 or higher.  The updated versions of Reflection Desktop will install a new ExtraCOM.Interop.dll to the programmer interfaces folder (C:\Program Files (x86)\Micro Focus\Reflection\Programmer Interfaces) and in the Microsoft Windows Global Assembly Cache (GAC). They will also install an ExtraCOM.Wrapper.dll and ExtraCOM.Wrapper64.dll to the main Reflection install folder (C:\Program Files (x86)\Micro Focus\Reflection). To use these updated files, the Application Programmer Interface must be selected for install in the Reflection Feature Tree (not a default installation option).

Here is a sample of updated VB.NET source code which reference the new EXTRACOM.Interop.  In the application project create the System object via "new" rather than via CreateObject("Extra.System") since the latter instantiates via the old EXTRACOM rather than the new EXTRACOM.Interop.  In your project/solution, it is important to reference the EXTRACOM.Interop.dll, otherwise the application will be unable to import the namespace listed at the top of the code below.

Imports EXTRACOM.Interop

Module Module1
    Sub Main()
        Dim sessions As Object, sess As Object
        ' this is the old method removed
        ' extrasystem = CreateObject("Extra.System")
        Dim extrasystem As New ExtraSystem

        sessions = extrasystem.Sessions

        ' change the session path to any existing .edp that is being used for testing
        sess = sessions.Open("C:\users\<username>\documents\Attachmate\EXTRA!\Sessions\Mainframe Demo Session.edp")
        sess.Screen.SendKeys("Hello")
    End Sub
End Module

Additional Information

Steps to Duplicate:

1. Install Reflection Desktop 16.1 with EXTRA! compatibility installed (the default).

2. Create a VB.NET "console" application.

3. Add either set of  the following code to the "sub main" for this test application:

    Sub Main()
        Dim sys As Object, sess As Object
        sys = CreateObject("extra.system")
        sess = sys.ActiveSession
        sess.Screen.SendKeys("Hello")
    End Sub

       or

    Sub Main()
        Dim sys As New EXTRACOM.ExtraSystem
        Dim sess As EXTRACOM.ExtraSession
        sess = sys.ActiveSession
        sess.Screen.SendKeys("Hello")
    End Sub

4. Run the application and the Exception Error will occur.