views:

769

answers:

3

I need to pass a Scripting.Dictionary between my C# app and another app. I would like to be able to create instances of and modify the dictionary in my C# app.

I know little about Scripting.Dictionary and ActiveX in general. Various forums suggest that I should use functions like System.Type.GetTypeFromProgID() and System.Activator.CreateInstance() to create an instance. Unfortunately this means that it's an opaque object to the rest of my code.

Is this really how it's supposed to be done or is there a better way? Ideally I'd like to import a compile-time type and just use it like any other type. Is this possible?

This article suggests I obtain a "metadata assembly" from the vendor - does anyone know if such an assembly exists for Scripting.Dictionary?

A: 

Create a wrapper dictionary class which implements IDictionary and which uses the Scripting.Dictionary as its internal storage implementation. Use the wrapper in your .NET code and pass the inner Scripting.Dictionary via COM to the other app.

Paul C
+2  A: 

I've just tried the easiest approach, and it seems to work:

Add a COM reference to the scrrun.dll in Visual Studio (it should show up in the COM tab of the Add References dialog), and Visual Studio will automatically create the interop files for you. You can then write code like this:

Scripting.Dictionary d = new Scripting.DictionaryClass();
d.Add( ref myKey, ref myValue );
MyComType.Method( d );

If you have any trouble with that, I can post some more examples, or perhaps a clarification.

Ant
A: 

I am facing the same problem please help me....

We are product development company and our existing application is in ASP, I am trying to send scripting.dictionary object to c#'s com visible class. I am using the System.Collections.Generic class here is my code

ASP: dim dictForm set dictForm=CreateObject("scripting.dictionary")

dictForm("First") ="one" dictForm("Second") ="two" SET OBJMSGBOX = Server.CreateObject("DictionarySerializer.DictionarySerializer") call OBJMSGBOX.ConvertDictionary(dictForm)

c#: [ComVisible(true)] public class DictionarySerializer : IXmlSerializable { Dictionary dict = new Dictionary(); public void ConvertDictionary(Dictionary dictionary) { this.dict = dictionary; } }

I am getting error Invalid procedure call or argument: 'ConvertDictionary'

Please tell me where I am going in wrong way.

Hi, welcome to StackOverflow! In order to get an answer to this, I suggest you use the "Ask Question" button in the top right - what you have done here is posted an _answer_, you're unlikely to get a response to it this way.
romkyns