dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
499 stars 191 forks source link

VS razor render issue backend codefile #9932

Closed bcheung4589 closed 7 months ago

bcheung4589 commented 8 months ago

Ive commented some code and all of sudden I get this issue, "Invalid expression term ';'". Now find me the offending ";".

This happens because I comment some code..

image image

What is also nice... is that when I uncomment the code, the error "Invalid expression term ';'" is still given.. image Now show me which ";" is giving me the error..

bcheung4589 commented 8 months ago

Also, on this whole page there is only 1 pair of <fieldset></fieldset> shown on the screen capture.

image

Now please explain why the hell Im still getting the error.. did VS become blind? Or is VS degraded so it doesnt know how comments work? This is really really REALLY frustrating.

bcheung4589 commented 8 months ago

When uncommenting code, it returns...??? VS now cant comment and uncomment? (ctrl-K-C / ctrl-K-U) what is happening?

image

davidwengier commented 8 months ago

Can you include the whole file contents, as text, in the issue? Or get a minimal repro in a basic new project? The error message mentions lambdas which normally means a specific construct, like a Razor template or RenderFragment, not just plain html. Without the extra context of the whole file I don't know that we'll be able to reproduce any issues here.

bcheung4589 commented 8 months ago

Sure thing:

<EditForm FormName="CreateRateForRelationForm" EditContext="FormEditContext" OnValidSubmit="SaveAsync">
    <FluentValidationValidator />
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Select a relation." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Relation <span class="text-danger required">*</span>
            </label>
        </div>
        <div class="col">
            <RelationPicker @bind-Value="Model.RelationId" />
            <ValidationMessage For="(() => Model.RelationId)" />
        </div>
    </div>
    <div class="row mb-3 align-items-center">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Import or export." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Import or export
            </label>
        </div>
        <div class="col">
            <div class="form-check form-check-custom form-check-solid form-switch">
                <InputCheckbox class="form-check-input me-1" @bind-Value="Model.IsExport" />
                <span class="text-muted">
                    @(Model.IsExport ? "EXPORT" : "IMPORT")
                </span>
            </div>
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Select a startdate." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Startdate <span class="text-danger required">*</span>
            </label>
        </div>
        <div class="col">
            <TariffDatePicker @bind-Value="Model.StartDate" IsRequired="true" />
            <ValidationMessage For="(() => Model.StartDate)" />
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Select a port." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Port of Discharge
            </label>
        </div>
        <div class="col">
            <PortPicker @bind-Value="Model.PortOfDischargeId" />
            <ValidationMessage For="(() => Model.PortOfDischargeId)" />
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Select a sailing area." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Sailing Area
            </label>
        </div>
        <div class="col">
            <SailingAreaPicker @bind-Value="Model.SailingAreaId" />
            <ValidationMessage For="(() => Model.SailingAreaId)" />
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Select an agent." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Agent
            </label>
        </div>
        <div class="col">
            <RelationPicker @bind-Value="Model.AgentId" />
            <ValidationMessage For="(() => Model.AgentId)" />
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Select a currency." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Currency
            </label>
        </div>
        <div class="col">
            <CurrencyPicker @bind-Value="Model.CurrencyId" />
            <ValidationMessage For="(() => Model.CurrencyId)" />
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Fill in the rate." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Rate
            </label>
        </div>
        <div class="col">
            <span class="fs-6">
                <input @bind="Model.CustomTariff" class="form-control form-control-solid" type="number" step=".01" min="0" />
                <ValidationMessage For="(() => Model.CustomTariff)" />
            </span>
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Fill in the minimum." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Minimum
            </label>
        </div>
        <div class="col">
            <span class="fs-6">
                <input @bind="Model.CustomMinimum" class="form-control form-control-solid" type="number" step=".01" min="0" />
                <ValidationMessage For="(() => Model.CustomMinimum)" />
            </span>
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Fill in the sale." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Measure Sale
            </label>
        </div>
        <div class="col">
            <span class="fs-6">
                <input @bind="Model.CustomMeasureSale" class="form-control form-control-solid" type="number" step=".01" min="0" />
                <ValidationMessage For="(() => Model.CustomMeasureSale)" />
            </span>
        </div>
    </div>
    <div class="row mb-3">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Fill in the factor." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Measure Factor
            </label>
        </div>
        <div class="col">
            <span class="fs-6">
                <input @bind="Model.MeasureFactor" class="form-control form-control-solid" type="number" step=".01" min="0" />
                <ValidationMessage For="(() => Model.MeasureFactor)" />
            </span>
        </div>
    </div>
    <div class="row mb-3 align-items-center">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Imo Tariff." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Is Imo Tariff
            </label>
        </div>
        <div class="col">
            <div class="form-check form-check-custom form-check-solid form-switch">
                <InputCheckbox class="form-check-input me-1" @bind-Value="Model.IsImoTariff" />
                <span class="text-muted">
                    @(Model.IsImoTariff ? "YES" : "NO")
                </span>
            </div>
        </div>
    </div>
    <div class="row mb-3 align-items-center">
        <div class="col-4 lh-lg">
            <HelpTextIcon Content="Upon Request." CssClass="ms-2" />
            <label class="fs-6 text-muted pt-1">
                Is Upon Request
            </label>
        </div>
        <div class="col">
            <div class="form-check form-check-custom form-check-solid form-switch">
                <InputCheckbox class="form-check-input me-1" @bind-Value="Model.IsUponRequest" />
                <span class="text-muted">
                    @(Model.IsUponRequest ? "YES" : "NO")
                </span>
            </div>
        </div>
    </div>

    @* actions row *@
    <div class="row mt-4">
        <div class="col">
            <button class="btn btn-secondary" type="button" @onclick="async () => await _dialog.CloseDialog()">Cancel</button>
            <button class="btn btn-info" type="button" @onclick="ConfirmAsync">Check Rate Exists</button>
            <SubmitSpinnerButton BtnCssClass="btn btn-success" IsLoading="IsLoading"></SubmitSpinnerButton>
        </div>
    </div>
</EditForm>

Commenting and uncommenting will show the errors captured with screenshots. As I was developing this page, I was commenting and uncommenting fields (rows).

chsienki commented 8 months ago

@jjonescz Please take a look. Thanks!

jjonescz commented 8 months ago

@bcheung4589 The error reporting is off, but it seems one of your lambdas is wrong. You can locate the problem by commenting out your lambdas until the problem disappears. Since you posted just the one file, I cannot tell which lambda is correct or wrong as I don't have the rest of the code.

@dotnet/razor-tooling The error is reported on an unmapped portion of the code like this:

image

What do you think is the best fix here? Should the compiler add a line pragma there - even though it's not actually user code? Or should razor tooling handle this?

davidwengier commented 8 months ago

There isn't a mapping issue here, the diagnostic is shown in the error list, and there is a squiggle in the IDE. Sometimes it sqiggles the whole file, but I'm not sure a line mapping would be able to do any better. The key thing, in my mind, is whether we can get a better error message for the user. ie, can we flag which lambda has the issue? It's not clear to me what the error even would be, but at least it explains why I couldn't repro it: I was simply creating a dummy Model class that had the appropriate properties on it.

Then again, perhaps we're not seeing the right issue, because we don't have the whole project. If commenting and uncommenting causes a problem, it seems unlikely that its a problem with lambdas. I'm assuming that, at least at some point, the file has no compile errors.

@bcheung4589 is there any way you can share the rest of the code? I understand if you can't post the whole thing on GitHub publically, but perhaps you can send through a minimal project that demonstrates the issue? Just hte one file in question, and supporting classes? If you want to email david.wengier at microsoft.com I can assure you it will be deleted once our investigation is completed.

dotnet-policy-service[bot] commented 7 months ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

Please see our Issue Management Policies for more information.