question

choi dong geun avatar image
choi dong geun asked

azure cloudscript cs0103 error

using System.Net.Security;
using System.Diagnostics;
using System;
using System.IO;
using System.Collections.Generic;
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.ServerModels;
using PlayFab.Json;
using PlayFab.DataModels;
using PlayFab.Internal;
namespace Company.Function
{
    public static class UpdateSession
    {
        [FunctionName("UpdateSession")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            var request = new UpdateUserInternalDataRequest
            {
                PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                Data = new Dictionary<string, string>()
                {
                    {"abc", "abc"}
                }
            };
            return await PlayFabServerAPI.UpdateUserInternalData(request);
        }
    }
}
return await PlayFabServerAPI.UpdateUserInternalData(request);

Error cs0103 comes out. I think I should write something in using, but I don't know what it is. What should I do?

I'm adjusting to azure. The documents are too scarce.

10 |1200

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

Made Wang avatar image
Made Wang answered

Firstly, you need to reference the two namespaces mentioned above. Secondly, the API of PlayFab is called asynchronously in c#, and UpdateUserInternalData has no response. I modified your code, you can refer to it.

It is worth mentioning that the commented part is the configuration of the environment. If you have already configured it, please ignore it. If you don't know how to configure it, you can refer to Where to set DeveloperSecretKey for Azure PlayFabServerAPI calls - Playfab Community.

using System.Net.Security;
using System.Diagnostics;
using System;
using System.IO;
using System.Collections.Generic;
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.ServerModels;
using PlayFab.Json;
using PlayFab.DataModels;
using PlayFab.Internal;

using PlayFab.Samples;
using PlayFab;

namespace Company.Function
{
    public static class UpdateSession
    {
        [FunctionName("UpdateSession")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
            var request = new UpdateUserInternalDataRequest
            {
                PlayFabId = context.CallerEntityProfile.Lineage.MasterPlayerAccountId,
                Data = new Dictionary<string, string>()
                {
                    {"abc", "abc"}
                }
            };
            //PlayFabSettings.staticSettings.TitleId = context.TitleAuthenticationContext.Id;
            //PlayFabSettings.staticSettings.DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY", EnvironmentVariableTarget.Process);
            await PlayFabServerAPI.UpdateUserInternalDataAsync(request);
            return null;
        }
    }
}

10 |1200

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

Made Wang avatar image
Made Wang answered

I noticed that you used the method of CS2AFHelperClasses.cs and the method of PlayFab, but did not reference them, please add a reference to them. As follows:

using PlayFab;

using PlayFab.Samples;

If you still have problems, please provide more detailed error messages.

1 comment
10 |1200

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

choi dong geun avatar image choi dong geun commented ·

The name ‘PlayFabServerAPI’ does not exist in the current context

0 Likes 0 ·

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.