C# exception System.ArgumentException in dynamic object


I have the following code interacting with automation server via dynamic object:

class Program
    static string strProgId = "MyAutomation.Document";
    static dynamic pserver = null;
    static void Main(string[] args)
            Type tPserver = Type.GetTypeFromProgID(strProgId);
            if (tPserver != null)
                pserver = Activator.CreateInstance(tPserver);
            pserver.About(null, 0);
            pserver.OpenDataFile(IntPtr.Zero, true, "Test.dat");
        catch (Exception e)
        if (pserver != null)

As you can see, it creates an instance of automation server and is calling two methods on it. The first call works as expected. The second call throws the following exception:

  e   {"Could not convert argument 0 for call to OpenDataFile."}  System.Exception {System.ArgumentException}
  Data    {System.Collections.ListDictionaryInternal} System.Collections.IDictionary> {System.Collections.ListDictionaryInternal} 
  HResult 0x80070057  int

I am not sure what is wrong here, since both methods have the same argument 0 and the first call works as expected. These methods are defined in ODL file as follows:

[id(20)] boolean About(long hWnd, long msgID);
[id(35)] boolean OpenDataFile(long hWnd, boolean bEmbed, BSTR* bsPfyFilePath );

Thank you for your help.

asked on Stack Overflow Feb 20, 2019 by Victor Havin

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0