Hello,
I cannot seem to correctly handle the response from Azure Functions. Currently, I'm having Functions read a JSON file, and passing it in it's entirety back to Unity/PlayFab. I can reserialize it using the dynamic type, and the resulting variable handles it correctly, I believe becoming of type JArray. (and by handling it correctly, I mean that the examining the variable in debugger, it shows keys and values as expected.)
However, if I try to deserialize to the class, either the result.FunctionResult.ToString(), or the variable that I deserialized it to, I receive the error (listed below).
I'm confident the data types in the json and class should be correct (no strings into ints), as I've worked with the data for a while. I've even tried manually hardcoding in a very simple json string to be passed back and deserialized, but recieved the same error.
I'm just very confused, because I'm studying the TicTacToe examples from github, and it seems like I'm doing it the same way. But I'll be very grateful if someone points out any errors!
Error
RuntimeBinderException: The best overloaded method match for 'PlayFab.Json.PlayFabSimpleJson.DeserializeObject<POI>(string, PlayFab.Json.IJsonSerializerStrategy)' has some invalid arguments (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,System.Type,object) System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet] (System.Runtime.CompilerServices.CallSite site, T0 arg0, T1 arg1) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0) DemoScript.<ContactFunctions>b__25_0 (PlayFab.CloudScriptModels.ExecuteFunctionResult result) (at Assets/PlayFabPartySDK/Examples/DemoScript.cs:309) PlayFab.Internal.PlayFabHttp+<>c__DisplayClass23_0`1[TResult].<_MakeApiCall>b__1 () (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:215) PlayFab.Internal.PlayFabUnityHttp.OnResponse (System.String response, PlayFab.Internal.CallRequestContainer reqContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:247) UnityEngine.Debug:LogException(Exception) PlayFab.Internal.PlayFabUnityHttp:OnResponse(String, CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:251) PlayFab.Internal.<Post>d__12:MoveNext() (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:198) UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
Azure Function (simplified)
[FunctionName("TestFunction1")] public static async Task<string> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, Binder binder, ILogger log) { string gameEvent = "Zmeer2103"; var eventDir = $"events/{gameEvent}/"; foreach (var filename in Enum.GetNames(typeof(DataFiles))) { var file = eventDir + gameEvent + '_' + filename + ".json"; using (var reader = await binder.BindAsync<TextReader>(new BlobAttribute(file, FileAccess.Read))) { string fileRead = reader.ReadToEnd(); dataString = fileRead; } } return dataString; }
C# Unity/PlayFab
public void ContactFunctions() { var request = new ExecuteFunctionRequest { FunctionName = "TestFunction1", }; PlayFabCloudScriptAPI.ExecuteFunction(request, (result)=> { // THIS WORKS var response = PlayFabSimpleJson.DeserializeObject<dynamic>(result.FunctionResult.ToString()); // THIS ERRORS POI suspects = PlayFabSimpleJson.DeserializeObject<POI>(response); // THIS WAS AN ATTEMPT TO HANDLE THE FULL JSON, WHICH HAS MANY OBJECTS in the class. // List<POI> suspects = new List<POI>(); // foreach(var poi in response["Suspects"]) // { // test = PlayFabSimpleJson.DeserializeObject<POI>(poi); // suspects.Add(test); // } }, onPlayFabError); }