cannot cast from source to destination type

0 votes

Hi, I am updating the storage using 5 calls in a row, data is in json format (key + array in a form of string). I do all this calls in a row, also they all have separate callback classes. Sometimes it works fine, sometimes it throws an exception "Exception : com.shephertz.app42.paas.sdk.csharp.App42Exception: System.InvalidCastException: Cannot cast from source type to destination type.". The data I am sending is the same, but sometimes it doesn't go through. If I set up a one second delay between each call - then it works without an exception, but the delay is too long in this case. The example code is below. What is the best solution for this case? Since it sometimes work, sometimes it does not (while the data is the same) - I do not think that it can not really cast something. 

storageService.AddOrUpdateKeys(dbName,"Games",gameToJoin,"{\"deck\":"deckk"}",new UnityCallBack1());

storageService.AddOrUpdateKeys(dbName,"Games",gameToJoin,"{\"hand1\":"+ hand11"}",new UnityCallBack2());

storageService.AddOrUpdateKeys(dbName,"Games",gameToJoin,"{\"hand2\":"hand22"}",new UnityCallBack3());

 

asked Apr 10, 2015 in App42 Cloud API-BaaS by Burda George (16 points)
Can you please share complete stack trace of the error ?
Write App42Log.SetDebug(true); in your Start method, which'll print the root cause of the error.
Exception : com.shephertz.app42.paas.sdk.csharp.App42Exception: System.InvalidCastException: Cannot cast from source type to destination type.
  at com.shephertz.app42.paas.sdk.csharp.storage.StorageResponseBuilder.BuildResponse (System.String json) [0x00000] in <filename unknown>:0
  at com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW.buildResponseForObjectService (System.String successValue, App42CallBack callBacK, System.String resource) [0x00000] in <filename unknown>:0
  at com.shephertz.app42.paas.sdk.csharp.connection.RESTConnectorWWW+<execute>d__6.MoveNext () [0x00000] in <filename unknown>:0
UnityEngine.Debug:Log(Object)
com.shephertz.app42.paas.sdk.csharp.App42Log:Console(String)
UnityCallBack6:OnException(Exception) (at Assets/Scripts/CloudStuff.cs:5482)
com.shephertz.app42.paas.sdk.csharp.connection.<execute>d__6:MoveNext()
com.shephertz.app42.paas.sdk.csharp.connection.<WaitForRequest>d__3:MoveNext()

1 Answer

0 votes

Hello Burda,

AddOrUpdateKey method is not a thread safe method and parallel request modification on the same key may result in this exception. You have to put the request in sequence to overcome this issue by putting delay on each request.

Thanks,

Himanshu Sharma

answered Apr 14, 2015 by hs00105 (2,005 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...