zHaytam / SmartBreadcrumbs

A utility library for ASP.NET Core (both MVC and Razor Pages) websites to easily add and customize breadcrumbs.
https://blog.zhaytam.com/2018/06/24/asp-net-core-using-smartbreadcrumbs/
MIT License
161 stars 77 forks source link

AmbiguousMatchException: Multiple custom attributes of the same type found. #18

Closed rutenio closed 5 years ago

rutenio commented 5 years ago

Hello. I'm having trouble setting up the service. In the file startup.cs I put: using SmartBreadcrumbs;   and service configuration: services.UseBreadcrumbs (GetType (). Assembly); But when build it, I get the error: AmbiguousMatchException: Multiple custom attributes of the same type found.

zHaytam commented 5 years ago

Hello! Can you please put the full error message?

rutenio commented 5 years ago

An error occurred while starting the application. AmbiguousMatchException: Multiple custom attributes of the same type found. System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit)

AmbiguousMatchException: Multiple custom attributes of the same type found. System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, bool inherit) System.Reflection.CustomAttributeExtensions.GetCustomAttribute(MemberInfo element) SmartBreadcrumbs.BreadcrumbsManager.Initialize(Assembly assembly, BreadcrumbOptions options) SmartBreadcrumbs.BreadcrumbExtensions.UseBreadcrumbs(IServiceCollection services, Assembly assembly, BreadcrumbOptions options) G2G.Startup.ConfigureServices(IServiceCollection services) in Startup.cs + services.UseBreadcrumbs(GetType().Assembly); Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services) Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize() Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()

zHaytam commented 5 years ago

And what about your actions (routes)? Are you adding multiple BreadcrumbAttributes to one of them by any chance?

rutenio commented 5 years ago

My only route setting is:
app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });

zHaytam commented 5 years ago

I mean your action methods (the ones with IActionResult)

rutenio commented 5 years ago

I haven't route config in my methods. I use the Default route. And I deleted the SmartbreadCrumb settings from the controllers and the error persists.

zHaytam commented 5 years ago

I don't really understand, do you not have actions in your whole website? Not even an Index?

rutenio commented 5 years ago

Of course I have: // GET: Tickets public async Task Index() { var tkt = await _context.Tickets.ToListAsync(); var cliente = _contextPri.Query().OrderBy(f => f.Nome).ToList();

        foreach (var item in tkt)
        {
            item.Cliente = cliente.Find(c => c.Id == item.ClienteId);
        }

        return View(tkt);
    }

I haven't extra routes settings.

rutenio commented 5 years ago

In short, even if I only change my startup.cs file and nothing else in my project, I get the error above.

zHaytam commented 5 years ago

I understand you but the error says you're using multiple Breadcrumb attributes on the same action. Please check.

rutenio commented 5 years ago

Okay. I started a new project to test and find out where I was going wrong. The DefaultBreadcrumb parameter was in the same controller as I wanted the breadcrumbs, which was not the HOME controller. I switched to the Home controller and it worked. I do not know exactly if it has a relationship, but now it works fine. I apologize, but the documentation was not very clear.