question

hak99922 avatar image
hak99922 asked

azure function

I'm trying to delete player account using azure function but I'm getting this error ..

Converting null literal or possible null value to non-nullable type.CS86

Can you help me on how to fix this?

6500-hhhh.png

here is the azure code

 using Microsoft.Azure.WebJobs;
 using Microsoft.Azure.WebJobs.Extensions.Http;
 using Microsoft.AspNetCore.Http;
 using Newtonsoft.Json;
 using PlayFab.Samples;
 using PlayFab;
 using PlayFab.AdminModels;
 using Microsoft.Extensions.Logging;
    
    
 namespace Company.Function
 {    public class DeltUsr
     {
         private readonly ILogger _logger;
    
         public DeltUsr(ILoggerFactory loggerFactory)
         {
             _logger = loggerFactory.CreateLogger<DeltUsr>();
         }
    
         [FunctionName("DeltUsr")]            
 public static async Task<PlayFab.PlayFabResult<DeleteMasterPlayerAccountResult>> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post",Route = null)] HttpRequestData req, ILogger log)
 {
     log.LogInformation("C# HTTP trigger function processed a request.");
     FunctionExecutionContext<dynamic> context = JsonConvert.DeserializeObject<FunctionExecutionContext<dynamic>>(await req.ReadAsStringAsync());
     var args = context.FunctionArgument;
     string playFabId = args["MasterID"];
    
     log.LogInformation(playFabId);
     var apiSettings = new PlayFabApiSettings{
         TitleId = Environment.GetEnvironmentVariable("PLAYFAB_TITLE_ID",EnvironmentVariableTarget.Process),
         DeveloperSecretKey = Environment.GetEnvironmentVariable("PLAYFAB_DEV_SECRET_KEY",EnvironmentVariableTarget.Process)
     };
        var adminApi = new PlayFabAdminInstanceAPI(apiSettings);
     var request = new DeleteMasterPlayerAccountRequest(){
         PlayFabId = playFabId};
    
     var ret = await adminApi.DeleteMasterPlayerAccountAsync(request);
     return ret;
 }
     }
        
        
    
 }

Empty warnings I get after adding this CS2AFHelperClasses.cs file

6513-ekran-goruntusu-2023-11-12-182148.png

unity3dCloudScript
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

·
Neils Shi avatar image
Neils Shi answered

The CS86 warning is triggered when there is a conversion of a null literal or possible null value to a non-nullable type. You can add some null checks in your code to fix it:

 var args = context.FunctionArgument;
 if (args != null && args["MasterID"] != null)
             {
               string playFabId = args["MasterID"];
             }
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.