question

yk avatar image
yk asked

The context variable always returns null

Hi all!

I'm trying to implement a call to an Azure function in a company project to work with PlayFab.

I'm studying the PlayFab CloudScript Context documentation: https://learn.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/quickstart https://learn.microsoft.com/en-gb/gaming/playfab/features/automation/cloudscript-af/cloudscript-af-context

Added this class to the project: https://github.com/PlayFab/PlayFab-Samples/blob/master/Samples/CSharp/AzureFunctions/CS2AFHelperClasses.cs

And I ran into a problem. When this code is executed, the context variable is always null.

 FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());

I tried other options:

 1) PlayerPlayStreamFunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<PlayerPlayStreamFunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());

 2) string json = await req.ReadAsStringAsync();
 FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(json);

The result is the same.

I was looking for answers on your forum. I tested everything I could find, but the context variable always returns null. https://community.playfab.com/questions/38743/how-to-get-functionexecutioncontext-inside-queue-f.html https://community.playfab.com/questions/58784/azure-function-functionexecutioncontext.html https://community.playfab.com/questions/84412/azure-functions-the-name-functioncontext-does-not.html https://community.playfab.com/questions/45899/azure-functions-context-return-null-scheduled-task.html

https://www.youtube.com/watch?v=ur42SwGkfy4

Why doesn't this code work? How should I fix it to get the context? 6365-screenshot-02.jpg

apis
screenshot-02.jpg (339.6 KiB)
screenshot-02.jpg (339.6 KiB)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

If you want to call Azure Function Cloud Script, then you need to use Execute Function to call it instead of running it locally. Just running the function locally won't interact with the PlayFab server and won't get the data you need, we recommend using Execute Function to call it as this doc shows: Server-Side Cloud Script - Execute Function - REST API (PlayFab CloudScript) | Microsoft Learn. The local running of Azure Function is not suitable for Azure Function Cloud Script, but it has its own local debugging method, you can refer to Local debugging for Cloudscript using Azure Functions - PlayFab | Microsoft Learn.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.