Click here to Skip to main content
14,981,456 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
I have a one dynamic object i want to change into user defined object how i can Serialize
this is controller code how i can change
dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email");
         string email =;
         string firstname = me.first_name;
         string middlename = me.middle_name;
         string lastname = me.last_name;

and i want to dynamic object into user defined how i convert i am trying like that

What I have tried:

var jsonData = JsonConvert.SerializeObject(me);
                        var dc = JsonConvert.DeserializeObject<User>(jsonData);
                        Session["User"] = dc;

and i am getting Error like this
Message = "Could not convert string to integer: 1404663032928561. Path 'id', line 1, position 66."
Updated 7-Jun-17 7:36am
Afzaal Ahmad Zeeshan 7-Jun-17 14:00pm
You can try using long type for this. :-) That would work, also if this is the client type then you can change the API consumption as needed. On the server-side it would be tough to rethink all of the possible ways to solve.

Or, are the server admin/developer as well?

1 solution

You've obviously declared your id property on your User class as an int, but the values returned from the API are too large to fit.

(A signed 32-bit integer can only store values up to 2147483647, which is significantly smaller than 1404663032928561.)

Change the property to be a string instead.
Aitzaz Ahsan 8-Jun-17 1:28am
Thank you @Richard i am crazy i did not think about that. thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900