C
C#5mo ago
Folo

Non-invocable member 'NotFound' cannot be used like a method.

I am trying to make an API
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using RoBotAPI.Models;
using RoBotAPI.Services;

namespace RoBotAPI.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class UsersController
{
private readonly UsersService _usersService;
public UsersController(UsersService usersService) =>
_usersService = usersService;

[HttpGet]
public async Task<List<User>> Get() =>
await _usersService.GetAsync();

[HttpGet("{id}")]
public async Task<ActionResult<User>> Get(ulong id)
{
var user = await _usersService.GetAsync(id);
return user ?? NotFound();
}
}
}
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using RoBotAPI.Models;
using RoBotAPI.Services;

namespace RoBotAPI.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class UsersController
{
private readonly UsersService _usersService;
public UsersController(UsersService usersService) =>
_usersService = usersService;

[HttpGet]
public async Task<List<User>> Get() =>
await _usersService.GetAsync();

[HttpGet("{id}")]
public async Task<ActionResult<User>> Get(ulong id)
{
var user = await _usersService.GetAsync(id);
return user ?? NotFound();
}
}
}
and I'm getting the error in the title in the GET {id} method and NotFound() is (quite funnily) not found. Is this an error with my ASP.NET install or something I'm doing wrong?
2 Replies
Jimmacle
Jimmacle5mo ago
public class UsersController you aren't inheriting from a base class that would have that method
Folo
Folo5mo ago
Ahhh, my bad, missed that part of the tutorial. Thanks!
Want results from more Discord servers?
Add your server
More Posts