N
NvrBst
I have a COM object with a RCW avalible via Web Service. My RCW
Interop dll is in my bin directory labled "Interop.ASMLib.dlI", and
"using ASMLib;" is at the top of my class. I can call any method like
so.
using ASMLib;
A1 - myClass o1 = (myClass)Server.CreateObject("ASM.myClass");
A2 - string ret = o1.get_Test(1, 1);
This works perfectly, however, I have a string s1 (IE s1 = "myClass"
in this example) avalible at runtime and would like to convert the
"Server.CreateObject(...)" object to the type labled in s1. I've
tried
B1 - object o1 = Server.CreateObject("ASM.myClass");
B2 - object o2 = Convert.ChangeType(o1, Type.GetType("ASMLib.myClass,
Interop.ASMLib, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null"));
It throws excpetion "System.InvalidCastException: Object must
implement IConvertible."
Since Line A1 and A2 work fine I'm sure there has to be a way I can
convert the Object to "myClass" at runtime without changing the COM
object? I got the AssemblyQualifiedName by echoing
"o1.AssemblyQualifiedName" in the Line A1 example, then using it in
the Lind B2 example. If anyone has some suggestions or explainations
I'd be very greatful
Thanks
NB
PS: I have a slight workaround which is just a huge switch() statment
that calls each COM method as labled in the A1A2 example using the
information I have at runtime (strings of class / method / params),
however, this is ~50 lines (a lot of types) while if I could convert
then invoke, it would reduce down to just a couple lines.
Interop dll is in my bin directory labled "Interop.ASMLib.dlI", and
"using ASMLib;" is at the top of my class. I can call any method like
so.
using ASMLib;
A1 - myClass o1 = (myClass)Server.CreateObject("ASM.myClass");
A2 - string ret = o1.get_Test(1, 1);
This works perfectly, however, I have a string s1 (IE s1 = "myClass"
in this example) avalible at runtime and would like to convert the
"Server.CreateObject(...)" object to the type labled in s1. I've
tried
B1 - object o1 = Server.CreateObject("ASM.myClass");
B2 - object o2 = Convert.ChangeType(o1, Type.GetType("ASMLib.myClass,
Interop.ASMLib, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null"));
It throws excpetion "System.InvalidCastException: Object must
implement IConvertible."
Since Line A1 and A2 work fine I'm sure there has to be a way I can
convert the Object to "myClass" at runtime without changing the COM
object? I got the AssemblyQualifiedName by echoing
"o1.AssemblyQualifiedName" in the Line A1 example, then using it in
the Lind B2 example. If anyone has some suggestions or explainations
I'd be very greatful
Thanks
NB
PS: I have a slight workaround which is just a huge switch() statment
that calls each COM method as labled in the A1A2 example using the
information I have at runtime (strings of class / method / params),
however, this is ~50 lines (a lot of types) while if I could convert
then invoke, it would reduce down to just a couple lines.