Page 1 of 1

Room myRoom = sfc.GetRoomByName(name) throws exception

Posted: 25 Feb 2009, 09:20
by Real McCoy
I tried

Code: Select all

Room myRoom = sfc.GetRoomByName(name);
or

Code: Select all

Room myRoom = (Room)sfc.GetRoomByName(name);
But I had exception anyway. What's wrong in my code or in my understanding?

Exception message is

Code: Select all

Unable to cast object of type 'System.Collections.DictionaryEntry' to type 'SmartFoxClientAPI.Data.Room'.

Posted: 25 Feb 2009, 13:22
by ThomasLund
You found a genuine bug. The internal loop casts a dictionary entry to a Room, where it should iterate over all roomList.Values instead.

If you want to compile it yourself, then the correct GetRoomByName method is:

Code: Select all

        public Room GetRoomByName(string roomName)
        {
            Room room = null;

            foreach (Room r in roomList.Values)
            {
                if (r.GetName() == roomName)
                {
                    room = r;
                    break;
                }
            }

            return room;
        }
I've ran through the code and checked all iterations over a hashtable, and found another bug like that as well as some of the documentation being wrong in that regard.

I'll make sure that fix comes out together with the 1.1 release.

BTW - did you get all my PM's? They are sitting in my forum outbox and I havent heard back from you.

/Thomas

Posted: 25 Feb 2009, 21:26
by Real McCoy
I used workaround same as you place here :)

Waiting for the new API version.

I found your PMs and answered you by email. Thank you!