'Route' is an ambiguous reference between 'Microsoft.AspNetCore.Components.RouteAttribute' and 'Microsoft.AspNetCore.Mvc.RouteAttribute'

Viewed 1598

I am using Attribute routing. I need both the assemblies reference. I've tried, but not worked for me. Does anyone know how to fix this? Here is my Controller code: Namespaces

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Task1CRUD.Repository;
using Task1CRUD.Model;

namespace Task1CRUD.Controllers
{

    [Route("api/[Controller]")]
    [ApiController]
    public class CustomerController:Controller
    {
            private readonly ICustomerRepository _customerRep;
            public CustomerController(ICustomerRepository customerRepository)
            {
                _customerRep = customerRepository;
            }

            // GET api/values
            [HttpGet("")]
            public async Task<List<Customer>> GetCustomers()
            {
                return await _customerRep.GetCustomers();
            }

    }
}
2 Answers

You can specify the full class name directly on the RouteAttribute like this:

[Microsoft.AspNetCore.Mvc.Route("api/[Controller]")]
[ApiController]
public class CustomerController:Controller
{
        private readonly ICustomerRepository _customerRep;
        public CustomerController(ICustomerRepository customerRepository)
        {
            _customerRep = customerRepository;
        }

        // GET api/values
        [HttpGet("")]
        public async Task<List<Customer>> GetCustomers()
        {
            return await _customerRep.GetCustomers();
        }

}

Simply add using RouteAttribute = Microsoft.AspNetCore.Mvc.RouteAttribute; if you need to use attribute from AspNetCore.Mvc or using RouteAttribute = Microsoft.AspNetCore.Components.RouteAttribute; - if from AspNetCore.Components.

I'd recomend you to download ReSharper.

Related