C
C#2mo ago
DeadnTangy

Unsure what this error means

I'm building an Azure Function on .Net 6 and this return snippet is giving me this error. I am new to C#
No description
7 Replies
Jimmacle
Jimmacle2mo ago
it means that a HttpResponseMessage is not a Task<IActionResult> can you share more code for context?
DeadnTangy
DeadnTangy2mo ago
sure its not long at all one second
reflectronic
reflectronic2mo ago
you have two mistakes here. one is that your method is not async. the other is that HttpResponseMessage is not what you use to respond from a web API
DeadnTangy
DeadnTangy2mo ago
using System; using System.Net; using System.IO; 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 System.Net.Http; using System.Text; using Microsoft.Azure.WebJobs.Extensions.CosmosDB; using System.Linq.Expressions; using Microsoft.Azure.Cosmos; namespace Company.Function { public static class getVisitorCounter { [FunctionName("getVisitorCounter")] public static Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, [CosmosDB(databaseName:"AzureResume",containerName:"Counter", Connection = "AzureResumeConnectionString", Id = "1", PartitionKey = "1")] Counter counter, [CosmosDB(databaseName:"AzureResume", containerName: "Counter", Connection = "AzureResumeConnectionString", Id = "1", PartitionKey = "1")] out Counter updatedCounter, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); updatedCounter = counter; updatedCounter.Count += 1; var jsonToRetun = JsonConvert.SerializeObject(counter); return new HttpResponseMessage(System.Net.HttpStatusCode.OK){ Content = new StringContent(jsonToRetun, Encoding.UTF8, "application/json") }; } } }
Jimmacle
Jimmacle2mo ago
i'm not familiar with azure functions but afaik you need an actual ASP.NET controller to use IActionResult
DeadnTangy
DeadnTangy2mo ago
i was reading about async and using await. if use async it gives an error for the updatedCounter. I was ignoring it for now
Jimmacle
Jimmacle2mo ago
but there's IResult for minimal apis that definitely exposes the right response types this looks like a relevant example https://learn.microsoft.com/en-us/azure/azure-functions/functions-scenarios?pivots=programming-language-csharp#build-a-scalable-web-api but you'd want to use https://learn.microsoft.com/en-us/dotnet/api/system.web.mvc.jsonresult?view=aspnet-mvc-5.2` instead of OkResult
Want results from more Discord servers?
Add your server
More Posts
HTTP Request Pending Time Unusually HighCan anyone throw out any ideas why my server (local dev) would hang on incoming http requests? I'm uMinimalApi vs Mvc - ValidationOfHeadersI have been playing around with MinimalApi, and was surprised to see that MinimalApi could not handlHow to get rid of nullable warning?What are the usual ways to get rid of these warnings? Do I have to check if everything is null beforyo im tied to make a game and there is problomtile class using System.Collections; using System.Collections.Generic; using TMPro; using UnityEnginNetArchTests Not Detecting Project Referencesanyone here familiar with netarchtests? I am trying to enforce clean architecture, and for some reasTrying to make a "Distributed SQLite" in C# and gRPC/Protobuf - don't know what to do nextHello, for a project that I am required to do, I need to make a simple distributed database system dUnable to get all the azure ad groups details which logged in user is a part of.I'm using Azure AD login for an app to login with Microsoft credentials and get the groups (and theiTesting my UserEdit Api endpoint using swagger fails and throws a code 400 responseI am trying to use Swagger to test my api endpoints but i get a code 400 when i test them. ``` [HttNative bindings to MacOS ObjC classes?It's very easy to have C bindings in C# on both Windows and Linux, but I'm really struggling to knowHow to get Windows.Storage.ProviderGood afternoon, I'm trying to use the namespace Windows.Storage.Provider (https://learn.microsoft.co