dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.36k stars 9.99k forks source link

[Blazor] System.InvalidOperationException: Object of type '..' does not have a property matching the name 'ref' #11083

Closed astecenko closed 5 years ago

astecenko commented 5 years ago

Blazor Server Side Using this version of ASP.NET Core 3.0.100-preview6-012264 Using nuget.config from https://github.com/dotnet/core-sdk

Create default blazor server side project Create simple component at SimpleTextBox.razor :

@using Microsoft.AspNetCore.Components

<input type="@InputType" 
    disabled="@IsDisabled" 
    bind="@Value" 
    placeholder="@Hint" 
    title="@Tooltip" />

@functions
{
    private bool isDisabled;
    private string valueText;
    private string tooltip;

    [Parameter]
    public bool IsDisabled
    {
        get => isDisabled;
        set
        {
            isDisabled = value;
          StateHasChanged();
        }
    }

    [Parameter]
    public string Value
    {
        get => valueText;
        set
        {
            valueText = value;
         StateHasChanged();
        }
    }

    [Parameter] public string Hint { get; set; }
    [Parameter] public string InputType { get; set; } = "text";

    [Parameter]
    public string Tooltip
    {
        get => tooltip;
        set
        {
            tooltip = value;
           StateHasChanged();
        }
    }
}

Add to default Counter.razor

...
<h1>Counter</h1>
<SimpleTextBox ref="test11" />
<p>Current count: @currentCount</p>
...
@functions {
private SimpleTextBox test11;
int currentCount = 0;
void IncrementCount()
    {
        currentCount++;
        test11.Value = "Test_Name";
    }
}

After Run and go to Counter page I see:

Microsoft.AspNetCore.Components.Browser.Rendering.RemoteRenderer: Warning: Unhandled exception rendering component: Object of type 'WebApplication2.Pages.SimpleTextBox' does not have a property matching the name 'ref'.

System.InvalidOperationException: Object of type 'WebApplication2.Pages.SimpleTextBox' does not have a property matching the name 'ref'.
   at Microsoft.AspNetCore.Components.ParameterCollectionExtensions.ThrowForUnknownIncomingParameterName(Type targetType, String parameterName)
   at Microsoft.AspNetCore.Components.ParameterCollectionExtensions.SetParameterProperties(ParameterCollection& parameterCollection, Object target)
   at Microsoft.AspNetCore.Components.ComponentBase.SetParametersAsync(ParameterCollection parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterCollection parameters)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.Rendering.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.Rendering.Renderer.ProcessRenderQueue()
Microsoft.AspNetCore.Components.Server.ComponentHub: Warning: Unhandled Server-Side exception

WAIDW

SteveSandersonMS commented 5 years ago

With preview 6, ref is now @ref:

<SimpleTextBox @ref="test11" />
accessibites commented 5 years ago

Hi,

I have the same problem.

I try to add a EditForm with a custom css class, adding the class attribute as a parameter in the component: <EditForm class="test" MOdel="@model" ... >

When I go to the page with the component, I get the following error:

InvalidOperationException: Object of type 'Microsoft.AspNetCore.Components.Forms.EditForm' does not have a property matching the name 'class'.

Am I doing something wrong?

Thanks!

SteveSandersonMS commented 5 years ago

@accessibites You must be using an older version of Blazor. Try updating to preview 8 or later.