Room myRoom = sfc.GetRoomByName(name) throws exception

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Room myRoom = sfc.GetRoomByName(name) throws exception

Postby Real McCoy » 25 Feb 2009, 09:20

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'.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 25 Feb 2009, 13:22

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
User avatar
Real McCoy
Posts: 21
Joined: 06 Dec 2008, 12:01

Postby Real McCoy » 25 Feb 2009, 21:26

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!

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 7 guests