© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Non-invocable member cannot be used like a method?
C#CC# / help
4y ago
✅ Non-invocable member cannot be used like a method
C#CC# / help
3y ago
Cannot find method although defined and used?
C#CC# / help
2y ago
Newly added resource cannot be used
C#CC# / help
2y ago