Invalid cast exception between WebGL and Mobile builds !

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Invalid cast exception between WebGL and Mobile builds !

Postby faisal007 » 02 Mar 2017, 16:24

Hi,

We Recently started porting our unity game from WebGL to mobile. This mostly consisted of UI changes and no changes to the SFS code were made, however we started encountering weird cast errors right away in the client side code.

Code: Select all

InvalidCastException: Cannot cast from source type to destination type.
Sfs2X.Entities.Variables.BaseVariable.GetIntValue ()
BuddyListController.OnBuddyVariablesUpdate (Sfs2X.Core.BaseEvent evt) (at Assets/Scripts/UIScripts/BuddyListController.cs:116)



The Client Side code is as follows:

Code: Select all

private void OnBuddyOnlineUpdate(BaseEvent evt)
    {
        bool isItMe = (bool)evt.Params["isItMe"];
        Buddy buddy = (Buddy)evt.Params["buddy"];

        if (!isItMe)
        {
            if (buddy.IsOnline)
            {
                Debug.Log(buddy.GetVariable("$userID").Type);
                int buddyID = buddy.GetVariable("$userID").GetIntValue();
}
}}


Server side code is:

Code: Select all

buddyVars.add(new SFSBuddyVariable("$userID", res.getSFSObject(i).getLong("user_id").doubleValue()));


the cast error happens when buddy.GetVariable("$userID").GetIntValue(); line is run. this is really confusing since this is working code in the WebGL Build. This is happening in a large amount of places in the code base.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid cast exception between WebGL and Mobile builds !

Postby Lapo » 02 Mar 2017, 18:27

Hi,
can you please specify which API version you're using and SFS2X version as well?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Invalid cast exception between WebGL and Mobile builds !

Postby faisal007 » 03 Mar 2017, 06:54

Server version: 2.9.0

C# API version: 1.7.2
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Invalid cast exception between WebGL and Mobile builds !

Postby Lapo » 03 Mar 2017, 08:12

2.9 is almost 3 years old, I would recommend updating the server at least to the latest 2.11.x update, which is only a patch and doesn't require a full install.
http://smartfoxserver.com/download/sfs2x#p=updates
(see bottom of page)

The reason being that we've fixed a couple of issues related with type conversions for webgl.
If the problem persists let us know.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
faisal007
Posts: 37
Joined: 27 Sep 2016, 09:01

Re: Invalid cast exception between WebGL and Mobile builds !

Postby faisal007 » 07 Mar 2017, 06:14

Alright i will post update after upgrading server version.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 18 guests