Index Server Catalogue Class

  • Thread starter Thread starter newsreader
  • Start date Start date
N

newsreader

I am curious if anybody has tried to create a Catalogue Class in C#.
Here is the code:
CIODMLib.AdminIndexServerClass oAdmin = new
CIODMLib.AdminIndexServerClass();
CIODMLib.CatAdmClass oCatAdmin;
oAdmin.MachineName = "MYSERVER";
if(oAdmin.IsRunning())
{
oCatAdmin = (CIODMLib.CatAdmClass)oAdmin.GetCatalogByName("MYDF");
//Error here
}
else
{
oAdmin.Start();
}

For some reason the runtime error message tells me that the cast is not
valid.

The modified code does not work either, the same exception "cast is not
valid":

CIODMLib.AdminIndexServerClass oAdmin = new
CIODMLib.AdminIndexServerClass();
object oCatAdmin;
oAdmin.MachineName = "MYSERVER";
if(oAdmin.IsRunning())
{
oCatAdmin = oAdmin.GetCatalogByName("MYDF");

MessageBox.Show(((CIODMLib.CatAdmClass)oCatAdmin).GetCatalogByName("MYCATALO
GUE"); //Error here
}
else
{
oAdmin.Start();
}

Anybody has any ideas how to deal with this?
 
I have found the solution to this.
One has to use Marshal.CreateWrapperOfType:
CIODMLib.AdminIndexServerClass oAdmin = new
CIODMLib.AdminIndexServerClass();

CIODMLib.CatAdmClass oCatAdmin;

oAdmin.MachineName = "DFSERVER";

if(oAdmin.IsRunning())

{

Type oType = typeof(CIODMLib.CatAdmClass);

object oObject = oAdmin.GetCatalogByName("MYDF");

object oWrapper = Marshal.CreateWrapperOfType(oObject, oType);

oCatAdmin = (CIODMLib.CatAdmClass)oWrapper;

MessageBox.Show(oCatAdmin.CatalogName);

}

else

{

oAdmin.Start();

}
 
Back
Top