Visual Studio 2019 - COM Exception: Member not found 0x80020003

-1

I'm using an Interop library as reference in Visual Studio 2019 which is able to execute the following code without any error:

using someInterop;
private void button1_Click(object sender, EventArgs e)
{
    var flexApp = new NSF.Application();
    var proxyScan = flexApp.Scan;

    proxyScan.StartPrescan();
    do
    {
        Console.WriteLine("Hello");
        System.Threading.Thread.Sleep(100);
    }
    while (proxyScan.IsScanningPrescan());
}

But, when I declare a class and define properties to represent variable (to make them global):

public class NSFApp
{
    public Application someApp { get; set; }
    public ProxyScan someScan { get; set; }

    public NSFApp()
    {
        someApp = new NSF.Application();
        someScan = someApp.Scan;
    }
}

and then use it in the application, it throws a COM Exception - Member not found 0x80020003

private void btnConnect_Click(object sender, EventArgs e)
{
    var nsf = new NSFApp();

    if (chkSimulation.Checked) { nsf.someApp.Simulation = true; }

    nsf.someScan.StartPrescan();
    
    do
    {
        Console.WriteLine("Hello");
        System.Threading.Thread.Sleep(100);
    }
    while (nsf.someScan.IsScanningPrescan());
}

Error details:

System.Runtime.InteropServices.COMException
  HResult=0x80020003
  Message=Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))
  Source=mscorlib
  StackTrace:
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Nanosurf_C3000.IProxyScan.IsScanningPrescan()
   at _AFMTestStub.Form1.btnConnect_Click(Object sender, EventArgs e) in C:\Form1.cs:line 83
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at _AFMTestStub.Program.Main() in C:\Program.cs:line 19

Unable to decipher the cause!

c#
.net
com
visual-studio-2019
asked on Stack Overflow Dec 2, 2020 by Mandeep Singh

1 Answer

0

Changing the variable to Dynamic did the magic.

Thank you Joseph! –

answered on Stack Overflow Dec 7, 2020 by Mandeep Singh

User contributions licensed under CC BY-SA 3.0