Hello.
Problem:
I'm getting a C# compiler error on my .aspx web page: CS0118: 'oMap' is a 'variable' but is used like a 'method' I am using a managed .net wrapper generated by TLBIMP.EXE for one of our COM components. As best as I can tell, the managed wrapper does not support properties in the COM IDL that have a dispatch id of 0 (using the DISPID_VALUE contant).
Code:
This is an example of the original JavaScript code that I am trying to convert:
var oMap = Server.CreateObject("util_Map");
oMap("key1") = "asdf";
oMap("key2") = "zxcv";
This is the C# migrated code on my .aspx web page that gets the compiler error:
util_Map oMap = new util_Map();
oMap("key1") = "asdf"; <-- CS0118: 'oMap' is a 'variable' but is used like a 'method'
oMap("key2") = "zxcv";
The IDL of the COM object is defined as such for these properties:
interface util_IMap : IDispatch
{
[
propput,
id(DISPID_VALUE),
helpstring("Add a key, value pair to the map.")
]
HRESULT Item([in] BSTR Key, [in] VARIANT Value);
[
propget,
id(DISPID_VALUE),
helpstring("Retrieve a key's value from the map.")
]
HRESULT Item([in] BSTR Key, [out, retval] VARIANT *pValue);
....
HOW DO I MIGRATE THIS CODE?
I've tried various permutations of the original code like oMap("key1", "asdf") or even oMap.set_Item("key1") = "asdf", but they just give different compiler errors. So, at this point, I can't use our legacy COM object with the managed wrapper.
Ideas?