C# .Net client library compatibility issues with 2.0 Beta
Hi Guys, this issue is not related to storing binary data. I upgraded my server to 2.0 beta today on windows 2008 server and my c# client which stores json objects in the data store is now showing the same encrypted string when i try to edit the document with the Admin UI!!!
I use the latest source code for the .net client from github and this is what the code and object class look like:
var user = new FbUser
{
UserName = String.IsNullOrEmpty(userName) ? id.ToString() : Util.Truncate(userName, 50).Trim(),
Bookmark = false,
IsFan = false,
UserPin = pin,
Email = Truncate(stremail, 150).Trim(),
CreatedTime = DateTime.Now
};
couchbaseClient.StoreJson(StoreMode.Replace, user.type + "_" + id, user);
public abstract class ModelBase
{
[JsonProperty("_id")]
public string Id { get; set; }
[JsonProperty("type")]
public abstract string type { get; }
[JsonProperty("rev")]
public abstract string rev { get; }
[JsonProperty("createdTime")]
public System.DateTime CreatedTime { get; set; }
}
Any ideas as to how to change the .net api so that your UI treats it as what it is! JSON.... since on 2.0 Beta Admin UI when I look at any record added by StoreJson, it shows it as a base64 encrypted string?!
I asked this question on the 2.0 Beta forum since another user had a base64 issue but they said it is related to sdk and i should ask here. I am using the latest source from github for both couch base, and enyim....
Thanks in advance
Hi John, as I had mentioned this has been working just fine up till DP4 and was broke since Bet 2.0 came out over a week ago. Nothing has changed on my code and the library is still the same...
Was there anything changed in the library to accommodate 2.0 either in couch base or in enyim libraries?
Anyways, since i didn't hear back from anyone, i downgraded back to DP4 and abandoned Bet 2.0!
There was another post from someone else who was seeing Base64 strings instead of the json content but i guess he had recommended a fix which modified two of your .js files in the Web Admin UI folder which actually did fix my problem too... His .js patches fixed the UI display of the json values, but the views still didnt work. That is why i went back to DP4 until the library or the 2.0 beta becomes more stable.
Thanks again
If you're seeing Base64 encoded strings for your document, then Couchbase Server sees the value you stored as invalid JSON. The Base64 string you see is your original stored item encoded. The SDK isn't doing anything special. With Couchbase Server DP4, if you stored invalid JSON you would have seen your document in the UI with a message "Invalid JSON."
However, I don't see your code as likely to produce invalid JSON. Is your StoreJson method the one from the getting started guide (which was updated with Beta) or the extension method?
Hi , yes it it that one you guys posted and updated with Beta... Pretty bizarre, isnt it!
Hi, I put some debug lines in your static json write and get functions and this is what it shows for both read/write. Please let me know what portion of this is NOT JSON as the couchbase engine thinks it is binary!!! what is missing? The other point to note is that i am using the latest version of Newtonsoft.json library, couchbase sdk, andenyim, and hammock libraries from github and I dont use your prepackaged .dll's...:
10/2/2012 9:21:13 AM Write JSON: {"type":"fbUser","rev":"\"2012-10-02T09:21:13.5 79477-07:00\"","userId":1,"loginDate":"\/Date(-62135568000000-0800)\/","credits" :99904.500000,"bookmark":false,"note":"Membership","owe":0.0,"owes":0.0,"userNam e":"Robot Dealer","userPin":"888","isFan":false,"fbSession":null,"deviceId":"Mem berCard","deviceType":"","deviceModel":"","deviceBrand":null,"clientIP":null,"cl ientBrowser":null,"activationKey":"mEMT8K576G5bKnwzaAVVp55un","fbSessionSecret": null,"isAppUser":true,"email":"","thumbnail":"","tableSeatedID":0,"tableSeatNo": 0,"tableExpires":"\/Date(-62135568000000-0800)\/","player1ID":0,"player2ID":0,"p layer3ID":0,"sessionPnL":0.0,"weeklyPnL":0.0,"monthlyPnL":0.0,"pnLYtd":0.0,"pnLL ifetime":0.0,"pnLDaily":0.0,"accessToken":"MemberCard","disableADs":false,"enabl eCMS":false,"enablePAN":false,"isDealer":true,"isRobot":true,"createdTime":"\/Da te(1342823728591-0700)\/"} 10/2/2012 9:21:13 AM Read JSON: {"type":"fbUser","rev":"\"2012-10-02T09:21:13.57 9477-07:00\"","userId":1,"loginDate":"/Date(-62135568000000-0800)/","credits":99 904.500000,"bookmark":false,"note":"Membership","owe":0,"owes":0,"userName":"Rob ot Dealer","userPin":"888","isFan":false,"fbSession":null,"deviceId":"MemberCard ","deviceType":"","deviceModel":"","deviceBrand":null,"clientIP":null,"clientBro wser":null,"activationKey":"mEMT8K576G5bKnwzaAVVp55un","fbSessionSecret":null,"i sAppUser":true,"email":"","thumbnail":"","tableSeatedID":0,"tableSeatNo":0,"tabl eExpires":"/Date(-62135568000000-0800)/","player1ID":0,"player2ID":0,"player3ID" :0,"sessionPnL":0,"weeklyPnL":0,"monthlyPnL":0,"pnLYtd":0,"pnLLifetime":0,"pnLDa ily":0,"accessToken":"MemberCard","disableADs":false,"enableCMS":false,"enablePA N":false,"isDealer":true,"isRobot":true,"createdTime":"/Date(1342823728591-0700) /"}
OK, so this appears to be a bug (or at least an unexpected behavior) on the server and not the client. Prior to recent builds (i.e., DP4) of Couchbase Server, the _id field was protected and couldn't be submitted as part of the JSON body. With the introduction of the meta (http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-server-rn_2...) the _id field was no longer supposed to be special and therefore allowable in documents.
If you remove the "_id" property from your ModelBase or replace it simply with "id" then the JSON is stored correctly.
I've opened a ticket, which you can track at http://www.couchbase.com/issues/browse/MB-6797.
Hi John, one more significant bug to report. I removed the _id as you had suggested and noticed the following which i had not seen before. the long UserId which is convered to string and stored as name differs what one another and i checked it before the call to Save and it was ok, this occurs duing save! some records show it as round down and some as round up but in neither case do they come out right!
{
"_id": "fbUser_634848234612614297",
"_rev": "1-0000600f87b2a10d0000034b00000112",
"$flags": 0,
"$expiration": 0,
"recType": "fbUser",
"userId": 634848234612614300,
"loginDate": "/Date(-62135568000000-0800)/",
"credits": 25,
"bookmark": false,
"note": "Membership",
"owe": 0,
"owes": 0,
"userName": "634848234612614297",
"userPin": "888",
"isFan": false,
if (Entities.Couchbase.couchbaseClient != null)
{
var user = new FbUser
{
//Id = key,
UserId = id,
IsDealer = isdealer,
IsRobot = isrobotic,
Owe = 0,
Owes = 0,
UserName = String.IsNullOrEmpty(userName) ? id.ToString() : Util.Truncate(userName, 50).Trim(),
};
Entities.Couchbase.couchbaseClient.StoreJson(StoreMode.Set, user.recType + "_" + id, user);
public static bool StoreJson(this CouchbaseClient client, StoreMode storeMode, string key, object value)
{
String json = JsonConvert.SerializeObject(value);
#if DEBUG
Console.WriteLine(DateTime.Now.ToString() + " Write JSON: " + json);
#endif
return client.Store(storeMode, key, json);
}Hi Joh, this major bug is in the Admin UI to display the wrong data for the longUserID field. The Get function returns the correct data. Please let the server team know this issue... thanks
If you're using the source from GitHub, are you able to step through the code? If you can, then if you examine the value of the json variable at https://github.com/couchbase/couchbase-net-client/blob/master/src/Couchb... do you see a valid JSON document being passed to the Store call?