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

Error when using components in if blazor server side #7258

Closed
1 task done
Alerinos opened this issue Apr 8, 2022 · 10 comments · Fixed by #11041
Closed
1 task done

Error when using components in if blazor server side #7258

Alerinos opened this issue Apr 8, 2022 · 10 comments · Fixed by #11041
Labels
area-compiler Umbrella for all compiler issues

Comments

@Alerinos
Copy link

Alerinos commented Apr 8, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

is if:
image
not if, work:
image

Code:

<Row>
    <Col Class="basis-8/12">
        <Card>
            <Title>Test</Title>
            <Content></Content>
        </Card>
    </Col>
    <Col Class="basis-4/12">
        test
    </Col>
</Row>

Row.razor

<div class="@Class flex flex-wrap md:mx-2">
    @ChildContent
</div>

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

    [Parameter]
    public string? Class { get; set; }
}

Col.razor

<div class="@Class @_sm @_md @_lg @_xl @_xxl basis-full mb-3 md:px-2">
    @ChildContent
</div>

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

    [Parameter]
    public string? Class { get; set; }

    private string _sm = string.Empty;
    private string _md = string.Empty;
    private string _lg = string.Empty;
    private string _xl = string.Empty;
    private string _xxl = string.Empty;

    [Parameter]
    public string? sm { set => _sm = $"sm:{value}"; }

    [Parameter]
    public string? md { set => _md = $"md:{value}"; }

    [Parameter]
    public string? lg { set => _lg = $"lg:{value}"; }

    [Parameter]
    public string? xl { set => _xl = $"xl:{value}"; }

    [Parameter]
    public string? xxl { set => _xxl = $"2xl:{value}"; }
}

Card.razor

<div class="@Class mb-2 bg-slate-600 dark:bg-zinc-800 text-white dark:text-gray-400">
    <div class="mx-2 md:mx-5 py-3">

        @* Title *@
        @if (Title is not null)
        {
            <div class="my-2 justify-center">
                <p class="text-3xl ">@Title</p>
            </div>
        }

        @* Content *@
        <div>
            @Content
        </div>

    </div>
</div>

@code {
    [Parameter]
    public RenderFragment? Title { get; set; }

    [Parameter]
    public RenderFragment? Content { get; set; }

    [Parameter]
    public string? Class { get; set; }
}

Error:
image

Błąd (aktywny) RZ1034 Found a malformed 'Col' tag helper. Tag helpers must have a start and end tag or be self closing.

What did I do wrong? I was looking for a solution but unfortunately I can't see it ..

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

.net core 7 preview 2

Anything else?

No response

@javiercn
Copy link
Member

@Alerinos thanks for contacting us.

Can you provide a minimal repro project as a public github repository so that we can make progress on this issue?

@ghost
Copy link

ghost commented Apr 10, 2022

Hi @Alerinos. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@Alerinos
Copy link
Author

@mkArtakMSFT mkArtakMSFT added the area-compiler Umbrella for all compiler issues label Apr 11, 2022
@mkArtakMSFT
Copy link
Member

Thanks @Alerinos.
@jaredpar this looks like a compiler issue. I think it's worth validating the repro provided to confirm that this indeed behaves as stated and take from there.

@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/aspnetcore Apr 12, 2022
@coader
Copy link

coader commented Jun 6, 2022

if has Col in code block, will show editor syntax error like above, but compiled and exectued is ok

@Alerinos
Copy link
Author

@coader Unfortunately, it is impossible to compile the code with VS.

@jaredpar Can something more be done in this direction?

@Alerinos
Copy link
Author

Alerinos commented Feb 3, 2023

@chsienki Can I ask for help? Unfortunately, many libraries including AntBlazor use this namespace, which causes problems when we want to give a condition.

@mkArtakMSFT I think in .net 8 we should take care of this.

@magierska
Copy link

@mkArtakMSFT Is there any update on this issue? For me it happens in some random cases when razor tag is put inside code block:
image
You'll see that exactly the same structure doesn't trigger an error outside code block, but does inside.

It's not only intellisense, it also blocks building for me.

@Alerinos
Copy link
Author

Alerinos commented Mar 25, 2024

@mkArtakMSFT Is there any update on this issue? For me it happens in some random cases when razor tag is put inside code block: image You'll see that exactly the same structure doesn't trigger an error outside code block, but does inside.

It's not only intellisense, it also blocks building for me.

Yes, change the name.

Nie naprawią tego szybko

@jjonescz
Copy link
Member

jjonescz commented Mar 26, 2024

This happens when all of the following is true:

  • a component is named like a void element, e.g., <Col>, <Link>,
  • it is not self-closed (<Link />) but has some content instead (<Link>content</Link>),
  • is used inside a code block (e.g., @{ }, @if (...) { }, @foreach (...) {}).

Also reported at #8460.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-compiler Umbrella for all compiler issues
Projects
None yet
7 participants