R
Robert Rotstein
I have a homework assignment to access a COM object from a .NET client,
get some information from it, then deterministically destroy it.
I search the registry for the directory of the object's CodeBase, then
load the .dll assembly via System.Reflection.Assembly.LoadFile(). I
search the assembly for all types and all members within each type for
the specific method name I'm looking for. I cast the MemberInfo object
I find to a MethodInfo object and then do
object theCOMobject =
Activator.CreateInstance(desiredFuction.DeclaringType);
After I extract the information that I want, I do a
System.Runtime.InteropServices.Marshal.ReleaseComObject(theCOMobject);
But this causes an exception:
"An unhandled exception of type 'System.InvalidCastException' occurred
in mscorlib.dll
Additional information: Specified cast is not valid."
What is the correct way to deterministically destroy the COM object?
Robert R.
get some information from it, then deterministically destroy it.
I search the registry for the directory of the object's CodeBase, then
load the .dll assembly via System.Reflection.Assembly.LoadFile(). I
search the assembly for all types and all members within each type for
the specific method name I'm looking for. I cast the MemberInfo object
I find to a MethodInfo object and then do
object theCOMobject =
Activator.CreateInstance(desiredFuction.DeclaringType);
After I extract the information that I want, I do a
System.Runtime.InteropServices.Marshal.ReleaseComObject(theCOMobject);
But this causes an exception:
"An unhandled exception of type 'System.InvalidCastException' occurred
in mscorlib.dll
Additional information: Specified cast is not valid."
What is the correct way to deterministically destroy the COM object?
Robert R.