Passing Key-Value pair to a COM method in C#

Posted by Sinnerman on Stack Overflow See other posts from Stack Overflow or by Sinnerman
Published on 2010-04-09T11:54:21Z Indexed on 2010/04/09 12:13 UTC
Read the original article Hit count: 351

Filed under:
|
|
|
|

Hello, I have the following problem: I have a project in C# .Net where I use a third party COM component.

So the problem is that the above component has a method, which takes a string and a number of key-value pairs as arguments. I already managed to call that method through JavaScript like that:

 var srcName
 srcName = top.cadView.addSource( 'Database', { driver : 'Oracle', host : '10.10.1.123', port : 1234, database : 'someSID', user : 'someuser', password : 'somepass' } )
 if ( srcName != '' )
 {
  ...
 }

... and it worked perfectly well. However I have no idea how to do the same using C#. I tried passing the pairs as Dictionary and Struct/Class but it throws me a "Specified cast is not valid." exception. I also tried using Hashtable like that:

     Hashtable args = new Hashtable();
        args.Add("driver", "Oracle");
        args.Add("host", "10.10.1.123");
        args.Add("port", 1234);
        args.Add("database", "someSID");
        args.Add("user", "someUser");
        args.Add("password", "samePass");

 String srcName = axCVCanvas.addSource("Database", args);

and although it doesn't throw an exception it still won't do the job, writing me in a log file

[ Error] [14:38:33.281] Cad::SourceDB::SourceDB(): missing parameter 'driver'

Any help will be appreciated, thanks.

© Stack Overflow or respective owner

Related posts about key

Related posts about value