System.InvalidCastException: Unable to cast object of type

Bin ich immer die folgende Fehlermeldung:

Unable to cast object of type 'Holo.Virtuellen.Zimmer.Bots.virtualBot' to type 'Holo.Virtuellen.Zimmer.Bots.virtualRoomBot'.

Hier ist mein code:

foreach (virtualRoomBot roomBot in _Bots.Values)  //Exception thrown here
{                    
    if (roomBot.goalX == -1)
        continue;

Holo.Virtuellen.Zimmer.Bots.virtualBot enthält:

public class virtualBot
{
    public virtualBot(int botID)
    {
        DataRow dRow;
        using (DatabaseClient dbClient = Eucalypt.dbManager.GetClient())
        {
            dRow = dbClient.getRow("SELECT * FROM roombots WHERE id = '" + botID + "'");
        }
        *There are values for the db here*
    }
}

Und Holo.Virtuellen.Zimmer.Bots.virtualRoomBot enthält:

public class virtualRoomBot
{
    internal virtualRoomBot(int botID, int roomID, int roomUID,
        virtualBot Bot, virtualRoomBotStatusManager statusManager)
    {
        this.botID = botID;
        this.roomID = roomID;
        this.roomUID = roomUID;
        this.Bot = Bot;
        this.statusManager = statusManager;
    }
  • virtualBot und virtualRoomBot sind zwei unterschiedliche und nicht Verwandte Arten. Sie können nicht direkt cast von einem zum anderen. Wenn _Bots.Values enthält eine Sammlung von Objekten des Typs virtualBot dann können Sie nicht behandeln Sie wie eine Sammlung von Objekten des Typs virtualRoomBot, was Sie zu tun versuchen. Darüber hinaus ist unklar, was es ist Sie versuchen zu tun, oder wo Sie _Bots.Values.
InformationsquelleAutor Mike | 2013-07-22
Schreibe einen Kommentar