Need help with my c# code

liter

New member
Joined
Sep 2, 2021
Messages
1
Programming Experience
1-3
C#:
namespace Vectigal.Invoice.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class InvoicesController : ControllerBase
    {
        private readonly InvoiceContext _context;
        public InvoicesController(InvoiceContext context)
        {
            _context = context;
        }
        // GET: api/Invoices
        [HttpGet]
        public async Task<ActionResult<IEnumerable<Invoice>>> GetInvoices()
        {
            return await _context.Invoices.ToListAsync();
        }

error CS0118: 'Invoice' is a namespace but is used like a type

 
Last edited by a moderator:

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,555
Location
Chesapeake, VA
Programming Experience
10+
Looks like you'll have to fully qualify the Invoice identifier on line 14 so that the compiler recognizes it as a type (likely declared in a different namespace), rather than the namespace named Invoice.

As a general rule, when creating namespaces, you'll want to use problem space (domain) names, rather than object names. So a better namespace should be "Invoicing" rather than "Invoice", while an object within the "Invoicing" namespace would be named "Invoice".
 
Last edited:
Top Bottom