A
Anton Shepelev
Hello all,
What is the right way to work with COM objects in .NET? I
usually do it this way:
public object GetValue( string query ) // analog of ExecuteScalar()
{ object Result = null;
Recordset rs = null;
rs = ( Recordset )cmp.GetBusinessObject( BoObjectTypes.BoRecordset );
try
{ rs.DoQuery( query );
if( rs.RecordCount > 0 )
{ rs.MoveFirst();
Result = rs.Fields.Item(0).Value;
}
}
finally
{ Marshal.ReleaseComObject( rs ); }
return Result;
}
where cmp and rs are COM objects exposed by a library which
is added to the project as a "COMReference". Even with this
pattern, I still sometimes get the error:
The Server threw an exception from HRESULT: 0x80010105
(RPC_E_SERVER_FAULT)
at the moment of creation ( GetBusinessObject() ), and some
have suggested it may be caused by incorrect memory
handling.
What is the right way to work with COM objects in .NET? I
usually do it this way:
public object GetValue( string query ) // analog of ExecuteScalar()
{ object Result = null;
Recordset rs = null;
rs = ( Recordset )cmp.GetBusinessObject( BoObjectTypes.BoRecordset );
try
{ rs.DoQuery( query );
if( rs.RecordCount > 0 )
{ rs.MoveFirst();
Result = rs.Fields.Item(0).Value;
}
}
finally
{ Marshal.ReleaseComObject( rs ); }
return Result;
}
where cmp and rs are COM objects exposed by a library which
is added to the project as a "COMReference". Even with this
pattern, I still sometimes get the error:
The Server threw an exception from HRESULT: 0x80010105
(RPC_E_SERVER_FAULT)
at the moment of creation ( GetBusinessObject() ), and some
have suggested it may be caused by incorrect memory
handling.