#Create CloudScript Context, Variables and Server SDKs build error

8 messages · Page 1 of 1 (latest)

dusky prairie
#

When I follow this documentation page: https://learn.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript-af/quickstart Specifically the "PlayFab CloudScript Context, Variables and Server SDKs" part, after creating a HelloWorld class copied from the code snippet and trying to build it. I get a bunch of "missing using directive" errors.

Z:\Azure\HelloWorld.cs(11,10): error CS0246: The type or namespace name 'FunctionNameAttribute' could not be found (are you missing a using directive or an assembly reference?) [Z:\Azure\Azure.csproj]
Z:\Azure\HelloWorld.cs(11,10): error CS0246: The type or namespace name 'FunctionName' could not be found (are you missing a using directive or an assembly reference?) [Z:\Azure\Azure.csproj]
Z:\Azure\HelloWorld.cs(13,85): error CS0246: The type or namespace name 'HttpRequest' could not be found (are you missing a using directive or an assembly reference?) [Z:\Azure\Azure.csproj]
Z:\Azure\HelloWorld.cs(14,13): error CS0246: The type or namespace name 'ILogger' could not be found (are you missing a using directive or an assembly reference?) [Z:\Azure\Azure.csproj]
Z:\Azure\HelloWorld.cs(13,14): error CS0246: The type or namespace name 'HttpTriggerAttribute' could not be found (are you missing a using directive or an assembly reference?) [Z:\Azure\Azure.csproj]
Z:\Azure\HelloWorld.cs(13,14): error CS0246: The type or namespace name 'HttpTrigger' could not be found (are you missing a using directive or an assembly reference?) [Z:\Azure\Azure.csproj]
Z:\Azure\HelloWorld.cs(13,26): error CS0103: The name 'AuthorizationLevel' does not exist in the current context [Z:\Azure\Azure.csproj]

PlayFab CloudScript using Azure Functions Quickstart Guide

#

Create CloudScript Context, Variables and Server SDKs build error

#

This is my azure.csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.1" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
    <PackageReference Include="PlayFabAllSDK" Version="1.185.240802" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>
last cedar
#

I ran into something that looked like this once, and clearing my nuget cache helped.

But also, I notice that your azure function app here is running on .net 8 in the isolated worker model evidenced by the output type being set to exe. That uses slightly different libraries than the in process worker model that used to be default. It's possible the tutorial is out of date. When I get a minute I'll run it and see if I encounter the same.

dusky prairie
last cedar
#

The PlayFab Tutorial links out to the getting started with Azure functions tutorial which is more generalized for azure and not specific to PlayFab. If my understanding is right here, its the PlayFab tutorial that needs to be updated and the code snippets for it are out of date. I'll give it a shot now and see how it turns out.

last cedar
#

Okay I set up fresh and saw the same issue following the quick start, it definitely needs to be updated. The code for the playfab hello world is meant to be used with a .net 6 function app running in the in process model. For the isolated model, use this sample code. I can't make any guarantees about it because it hasn't gone through testing, but it builds.

#
using Newtonsoft.Json;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using PlayFab;
using PlayFab.Samples;
using PlayFab.DataModels;

namespace My.Functions
{
    public class HttpExample
    {
        private readonly ILogger<HttpExample> _logger;

        public HttpExample(ILogger<HttpExample> logger)
        {
            _logger = logger;
        }

        [Function("HelloWorld")]
        public async Task<dynamic> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest req)
        {
            var reader = new StreamReader(req.Body);
            string requestContextBody = await reader.ReadToEndAsync();
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(requestContextBody);

            dynamic args = context.FunctionArgument;

            var message = $"Hello {context.CallerEntityProfile.Lineage.MasterPlayerAccountId}!";
            _logger.LogInformation(message);

{additional logic here}

            return new { messageValue = message };
        }
    }
}