A
Andrew Todd
I've got a problem with the scope of a variable, consider
the following example:
MyCOMObject.MyObjectClass obj;
try
{
obj = new MyCOMObject.MyObjectClass();
returnXml = obj.getEnquiryUsers();
}
catch (Exception e)
{
//handle error
}
finally
{
if (obj!=null)
{
Marshal.ReleaseComObject(obj);
obj = null;
}
}
This won't compile, it tells me that the variable obj is
unassigned when I test if it's null in the finally
statement.
This doesn't seem correct to me; I need to release the
COM object in the finally statement as if there is an
error in the try block the object will never be released.
These steps work in Java and are the steps we normally
take when interfacing with COM objects, is this a bug?
Thanks
Andrew
the following example:
MyCOMObject.MyObjectClass obj;
try
{
obj = new MyCOMObject.MyObjectClass();
returnXml = obj.getEnquiryUsers();
}
catch (Exception e)
{
//handle error
}
finally
{
if (obj!=null)
{
Marshal.ReleaseComObject(obj);
obj = null;
}
}
This won't compile, it tells me that the variable obj is
unassigned when I test if it's null in the finally
statement.
This doesn't seem correct to me; I need to release the
COM object in the finally statement as if there is an
error in the try block the object will never be released.
These steps work in Java and are the steps we normally
take when interfacing with COM objects, is this a bug?
Thanks
Andrew