C# implicitly convertion??

18/05/2005 - 06:40 por Eranga | Informe spam
My Error is " Cannot implicitly convert type 'object'
to'CIODMLib.CatAdmClass' "
The code segment is as follows;
public class Indexing
{
protected CIODMLib.AdminIndexServerClass admNew;
protected CIODMLib.CatAdmClass catNew;

public Indexing()
{
admNew = new CIODMLib.AdminIndexServerClass();
catNew = new CIODMLib.CatAdmClass();
}
public object InitializeCatalog(string strName, string strLoc)
{
admNew.AddCatalog(strName, strLoc);
return admNew.GetCatalog();
}
public void AddNewScope(string strName)
{
catNew = admNew.GetCatalogByName(strName);
}
}
public class IndexingAp
{
public static void Main(String[] args)
{
Indexing newAdm = new Indexing();
Indexing newCat = new Indexing();

newAdm.InitializeCatalog("myCat","C:\\myCatalogFolder");
newCat.AddNewScope("myCat");
}
}

I even tried
"catNew = (CIODMLib.CatAdmClass)admNew.GetCatalogByName(strName);"
Then error "'System.InvalidCastException' occurred Specified cast is not
valid." occurs
Can some one please help me???



*** Sent via Developersdex http://www.developersdex.com ***

Preguntas similare

Leer las respuestas

#1 Octavio Hernandez
18/05/2005 - 12:54 | Informe spam
I'm not familiar with the CIODMLib library so I cannot tell you exactly what
the problem is, but there are some clear facts from your code:

a) The GetCatalogByName() method returns an Object, so you must do an
explicit cast to the type you know you're going to receive.
b) The call you made to the GetCatalogByName() method DID NOT RETURN a
CatAdmClass object; otherwise the typecast you attempted (the correct way to
handle such situations) would have succeeded.

I suggest you to check the documentation of the library.

Best regards,

Octavio

"Eranga" escribió en el mensaje
news:OT%


My Error is " Cannot implicitly convert type 'object'
to'CIODMLib.CatAdmClass' "
The code segment is as follows;
public class Indexing
{
protected CIODMLib.AdminIndexServerClass admNew;
protected CIODMLib.CatAdmClass catNew;

public Indexing()
{
admNew = new CIODMLib.AdminIndexServerClass();
catNew = new CIODMLib.CatAdmClass();
}
public object InitializeCatalog(string strName, string strLoc)
{
admNew.AddCatalog(strName, strLoc);
return admNew.GetCatalog();
}
public void AddNewScope(string strName)
{
catNew = admNew.GetCatalogByName(strName);
}
}
public class IndexingAp
{
public static void Main(String[] args)
{
Indexing newAdm = new Indexing();
Indexing newCat = new Indexing();

newAdm.InitializeCatalog("myCat","C:\\myCatalogFolder");
newCat.AddNewScope("myCat");
}
}

I even tried
"catNew = (CIODMLib.CatAdmClass)admNew.GetCatalogByName(strName);"
Then error "'System.InvalidCastException' occurred Specified cast is not
valid." occurs
Can some one please help me???



*** Sent via Developersdex http://www.developersdex.com ***
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una preguntaRespuesta Tengo una respuesta
Search Busqueda sugerida