Skip to content

Namespace mismatched compilation error to the generic type component event arguments #12116

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

Closed
ajithr opened this issue Jul 12, 2019 · 3 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@ajithr
Copy link

ajithr commented Jul 12, 2019

Describe the bug

When using generic type to the Blazor component, the namespace is mismatched for EventCallback method arguments and throws compilation error.

MyGenComponent.razor:

@using GenericTypeBlazor.Shared.Models;

@typeparam T;

    <div>
        <ul>
            @ChildContent
        </ul>
    </div>


@code {
    [Parameter]
    protected RenderFragment ChildContent { get; set; }

    [Parameter]
    public IEnumerable<T> Data { get; set; }

    [Parameter]
    public EventCallback<EventArgsData<T>> EventOne { get; set; }

    [Parameter]
    public EventCallback<EventArguments> EventTwo { get; set; }
}

Models.cs

namespace GenericTypeBlazor.Shared.Models
{
    public class EventArgsData<T>
    {
        public bool IsRendered { get; set; }

        public T Data { get; set; }
    }

    public class EventArguments
    {
        public bool IsRendered { get; set; }

        public object Data { get; set; }
    }
}

Index.razor:

@page "/"
@using GenericTypeBlazor.Shared.Models;

<MyGenComponent Data="@MyData" EventTwo="@Event2"></MyGenComponent>

@code {
    public List<string> MyData = new List<string>() { "a", "b", "c", "d" };

    public void Event2(EventArguments args)
    {

    }
}

To Reproduce

Steps to reproduce the behavior:

  1. Clone the below Github repository.

https://github.com/ajithr/BlazorGenericType

  1. Run this application and it will throws the below error

1>obj\Debug\netcoreapp3.0\Razor\Pages\Index.razor.g.cs(103,295,103,301): error CS0234: The type or namespace name 'Shared' does not exist in the namespace '__Blazor.GenericTypeBlazor' (are you missing an assembly reference?)

Expected behavior

The EventCallback should be work with both generic type and non generic type arguments when using @typeparam in the Blazor component.

Screenshots

image

Additional context

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview6-012264
 Commit:    be3f0c1a03

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview6-012264\

Host (useful for support):
  Version: 3.0.0-preview6-27804-01
  Commit:  fdf81c6faf

.NET Core SDKs installed:
  1.1.13 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.1.700-preview-009618 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
  3.0.100-preview6-012264 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview6.19307.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview6-27804-01 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

@Faolan-dimplex
Copy link

@ajithr Thanks, was having trouble reproducing exactly what caused the error

@mkArtakMSFT
Copy link
Contributor

Thanks for all the details, @ajithr.
We'll try to repro this and update this issue accordingly.

@mkArtakMSFT mkArtakMSFT modified the milestones: 3.0.0-preview9, 3.1.0 Jul 17, 2019
@mkArtakMSFT mkArtakMSFT modified the milestones: 3.1.0, 3.0.0-preview9 Aug 5, 2019
@pranavkm pranavkm added bug This issue describes a behavior which is not expected - a bug. and removed investigate labels Aug 7, 2019
pranavkm added a commit to dotnet/razor that referenced this issue Aug 8, 2019
The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes dotnet/aspnetcore#12116
pranavkm added a commit to dotnet/razor that referenced this issue Aug 8, 2019
The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes dotnet/aspnetcore#12116
pranavkm added a commit to dotnet/razor that referenced this issue Aug 12, 2019
The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes dotnet/aspnetcore#12116
pranavkm added a commit to dotnet/razor that referenced this issue Aug 13, 2019
The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes dotnet/aspnetcore#12116
@pranavkm pranavkm added Done This issue has been fixed and removed Working labels Aug 13, 2019
@MajdajkD
Copy link

Possibly somewhat related to #13220 ?

@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
JunTaoLuo pushed a commit that referenced this issue May 7, 2020
The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes #12116
JunTaoLuo referenced this issue May 17, 2020
…t/razor#946)

The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes https://github.com/aspnet/AspNetCore/issues/12116\n\nCommit migrated from dotnet/razor@f0e09e4
dougbu referenced this issue in dougbu/razor-compiler Nov 17, 2021
…t/razor#946)

The code-generated TypeInference type resides in a custom namespace.
Any types that it refers to in user code must be qualified using the "global::" prefix
to avoid type \ namespace conflicts.

Fixes https://github.com/aspnet/AspNetCore/issues/12116\n\nCommit migrated from dotnet/razor@f0e09e4

Commit migrated from dotnet/aspnetcore@32196f8023a1
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests

6 participants