Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Reflection.AmbiguousMatchException #4

Closed
phidiassj opened this issue Jun 12, 2024 · 5 comments
Closed

System.Reflection.AmbiguousMatchException #4

phidiassj opened this issue Jun 12, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@phidiassj
Copy link

hello.

I tried using this library in my Blazor 8 hybrid project. I only added the @Attribute [Sitemap] directive to a few pages. There were no errors during compilation and execution, but when I navigate to sitemap.xml, I encounter the following error. I would appreciate any suggestions anyone could provide!

System.Reflection.AmbiguousMatchException: Multiple custom attributes of the same type 'Microsoft.AspNetCore.Components.RouteAttribute' found.
at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](MemberInfo element)
at Sidio.Sitemap.Blazor.SitemapMiddleware.CreateSitemap(IComponentBaseProvider componentBaseProvider)
at Sidio.Sitemap.Blazor.SitemapMiddleware.InvokeAsync(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

@marthijn
Copy link
Owner

Hi, could you provide some code so I can reproduce the issue? Thanks!

@phidiassj
Copy link
Author

phidiassj commented Jun 13, 2024

Hi, Thanks for your reply.
I found that the problem came from I am using a custom component to redirect the 404 URL.

Routes.razor

<Router AppAssembly="typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly }">
    <Found Context="routeData">
        <RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
        <FocusOnNavigate RouteData="routeData" Selector="h1" />
    </Found>
    <NotFound>
        <PageTitle>Not found</PageTitle>
        <LayoutView Layout="@typeof(Layout.MainLayout)">
            <SidioSitemapBlazorTest.Components.Pages.NotFoundPage />
        </LayoutView>
    </NotFound>
</Router>

NotFoundPage.razor

@page "/pagenotfound"
@page "/pagenotfound/{httpcode}"
@inject IJSRuntime jsRuntime
@rendermode InteractiveServer

<h5 style="text-align:center;">This URL do not exist...Redirecting...</h5>

@code {
    [Parameter]
    public string? httpcode { get; set; }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            var uri = navManager.ToAbsoluteUri("/");
            int redirectAfterMs = 1000;

            await jsRuntime.InvokeVoidAsync("redirectToLocalUri", uri, redirectAfterMs);
        }
    }
}

@marthijn
Copy link
Owner

Thanks. I'll look into it next week.

@phidiassj
Copy link
Author

Hello, I think I made a mistake, after further experimentation I discovered that the problem was not from custom components, but from multiple routes.
You only need to use more than one page attribute on the same component to cause this problem.
Some thing like:

@page "/pagenotfound"
@page "/pagenotfound/{httpcode}"

@marthijn marthijn self-assigned this Jun 16, 2024
@marthijn marthijn added the bug Something isn't working label Jun 16, 2024
@marthijn
Copy link
Owner

marthijn commented Jun 16, 2024

@phidiassj the issue has been resolved in release 1.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants