Aspnetcore: [Blazor] preview8 @ref codegen field does work in intellisense but not on build

Created on 13 Aug 2019  路  13Comments  路  Source: dotnet/aspnetcore

Describe the bug

The automatic field generation for @ref does work inside visual studio intellisense but not when building the project.

To Reproduce

Steps to reproduce the behavior:

  1. Using dotnet 3.0.100-preview8-013656 and VS 16.3.0 Preview 2.0
  2. Create new blazor server-side project.
  3. Add @ref="ele" to an element inside of the Counter component
  4. Reference the field inside of @code. E.g. ele.ToString();
  5. Intellisense is working fine.
  6. Build results in error: Pages\Counter.razor(14,9,14,12): error CS0103: Der Name "ele" ist im aktuellen Kontext nicht vorhanden.

Expected behavior

Code should compile.

Screenshots

image

Additional context

Workaround is to @ref:suppressField="ele" and add the field manually.

.NET Core SDK (gem盲脽 "global.json"):
 Version:   3.0.100-preview8-013656
 Commit:    8bf06ffc8d

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\

Host (useful for support):
  Version: 3.0.0-preview8-28405-07
  Commit:  d01b2fb7bc

.NET Core SDKs installed:
  2.1.701 [C:\Program Files\dotnet\sdk]
  2.1.801 [C:\Program Files\dotnet\sdk]
  3.0.100-preview8-013656 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview8.19405.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Done area-blazor bug

Most helpful comment

Lol, so no one tested this new feature before releasing it?

All 13 comments

@NTaylorMullen can you please look into this? Please try to repro this, if you can and we'll see what's going on then.

Yes I can confirm the issue. A workaround is needed as this will break a lot of projects.

Same here. Serious bug.

As a workaround you can add the @ref:suppressField to revert to the old behaviour

Yup. The feature doesn't work.

blazor-error-2

the workaround not work for (but i'm not really how to use it)
I precise i have a separate cs file for the ViewModel of my razor components
<input type="password" class="form-control" @bind-value="this.Model.Password" @bind-value:event="oninput" @onkeydown="@OnKeyDownPassword" @ref:suppressField="@inputPassword" /> protected ElementReference inputPassword { get; set; }

It build, but when i launch it i have this error in the chrome console
Uncaught (in promise) DOMException: Failed to execute 'setAttribute' on 'Element': '@ref:suppressfield' is not a valid attribute name.

anybody success tu use the workaround ?

thanks !

@julienGrd
Use it like this

<Show @ref="_showRef"  @ref:suppressField Number="Number" />

@julienGrd
Use it like this

<Show @ref="_showRef"  @ref:suppressField Number="Number" />

thanks it works ! i was pretty sure i was not using the good syntax :-)

Ya I can reproduce this, working on a fix. @shirhatti @danroth27 we should update the blog post (and anywhere else relevant) to mention that this feature does not work as intended.

Does anyone have a repro that causes a compiler crash?

Any chance for a patch/hotfix/new build ?

Sorry folks to do this, but here's the latest: https://github.com/aspnet/Announcements/issues/381

Lol, so no one tested this new feature before releasing it?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kevenvz picture Kevenvz  路  3Comments

BrennanConroy picture BrennanConroy  路  3Comments

markrendle picture markrendle  路  3Comments

aurokk picture aurokk  路  3Comments

rynowak picture rynowak  路  3Comments