Previously after some struggling I had managed to make a getObject and a setObject function work in java-script cloud script but I was advised to make them using azure cloud script instead. But I'm struggling to make these work too.
Here is my attempt at doing the function.
using System; using System.IO; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using PlayFab; using PlayFab.Samples; using PlayFab.Json; using PlayFab.DataModels; namespace My.Function { public static class GetChat { [FunctionName("getChat")] public static async Task<IActionResult> getChat( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# getChat function processed a request."); FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync()); var args = context.FunctionArgument; var entityProfile = context.CallerEntityProfile; var getObjectRequest = new GetObjectsRequest { Entity = ClassConverter<PlayFab.ProfilesModels.EntityKey, PlayFab.DataModels.EntityKey>.Convert(entityProfile.Entity) }; var dataApi = new PlayFabDataInstanceAPI(context.FunctionArgument); var getObjectsResponse = await dataApi.GetObjectsAsync(getObjectRequest); var getObjectsResult = getObjectsResponse.Result.Objects; return new OkObjectResult(new { profile = entityProfile, getResult = getObjectsResult }); } } public class ClassConverter<SourceClass, TargetClass> { public static TargetClass Convert(SourceClass input) { var json = PlayFabSimpleJson.SerializeObject(input); return PlayFabSimpleJson.DeserializeObject<TargetClass>(json); } } }
I inspired my self from the MakeEntityAPICall function in these sample functions:
but i read somewhere these samples where outdated and I should avoid using PlayFab.Plugins.CloudScript;
so I changed the
var context=await FunctionContext<dynamic>.Create(req);
in to
FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
from the CS2AFHelperClasses.cs script.
and few other things for it to compile.
Currently I get an error which I traced to this this simple variable call that causes the error: entityProfile.Entity
here is the terminal output in vs code:
[2022-04-25T18:31:50.498Z] Executed 'getChat' (Failed, Id=5d8f8068-8777-4c22-9bcd-7d1a53ca93d4, Duration=85ms)[2022-04-25T18:31:50.499Z] System.Private.CoreLib: Exception while executing function: getChat. PlayFabServerScipts: Object reference not set to an instance of an object.
I think I have everything properly setup in vs code since I can make simple functions with nothing in them work when testing localy:
Asides from just guess work I'm struggling to find ways to solve this.
Thanks in advanced for any help.