Auto increment function with Http trigger

Ahmed Waeli 1 Reputation point

i have this code in an Azure function with an Http trigger that reads from an storage table with one record. it gives me "an internal server error 500" all the time and nothing else. any help would be greatly appreciated

r "Microsoft.WindowsAzure.Storage"

r "Newtonsoft.Json"

using System.Net;
using System.Globalization;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<IActionResult> Run(HttpRequest req, CloudTable countTable, ILogger log)
// Get the name prefix
string prefix = req.Query["prefix"];
// Get the current count
TableOperation retrieveOperation = TableOperation.Retrieve("A", "A");
TableResult result = await countTable.ExecuteAsync(retrieveOperation);
DynamicTableEntity row = (DynamicTableEntity) result.Result;
EntityProperty current;
row.Properties.TryGetValue("CurrentCount", out current);
// Increment
// Save the incremented value
TableOperation replaceOperation = TableOperation.Merge(row);
await countTable.ExecuteAsync(replaceOperation);
// Return the name
GeneratedName newName = new GeneratedName {
Name = prefix + current.Int32Value.Value.ToString("D8")
log.LogInformation($"Generated name: {newName.Name}");
return new JsonResult(newName);
public class GeneratedName
public string Name;

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,012 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 66,991 Reputation points

    @Ahmed Waeli For any issue I will suggest you to review the application insights logs to get more details on the exception message to know the root cause of the error if you have configured the application insights on your function app.
    I will also suggest you to review the Diagnose and solve problems blade which will help you to know the cause for 500 errors along with the possible solution to mitigate the issue.

    If you still not able to find the root cause of 500 error then please let me know so I can assist you further.