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

Blazor wasm: RZ9991 build error when updating from 7.0.203 to 7.0.302 sdk #8725

Closed
1 task done
almightyju opened this issue May 17, 2023 · 12 comments
Closed
1 task done
Labels
area-compiler Umbrella for all compiler issues bug Something isn't working needs more info no recent activity

Comments

@almightyju
Copy link

almightyju commented May 17, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using a control WrappedSwitch that extends another control WrappedCheckbox which then extends InputBase<bool> using the WrappedSwitch with @bind-Value="SomeBool" will compile ok in 7.0.203 but in 7.0.302 results in:

error RZ9991: The attribute names could not be inferred from bind attribute 'bind-Value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.

Expected Behavior

The code should compile in both sdk vesions

Steps To Reproduce

Create a new blazor wasm project from a template.

In the shared folder create the following controls:

WrappedCheckbox

@using System.Diagnostics.CodeAnalysis
@inherits InputBase<bool>

<div class="form-check @WrapperDivCSS">
	<input id="@Id" class="form-check-input" type="checkbox" @bind="CurrentValue" @attributes="AdditionalAttributes" />
	<label class="form-check-label" for="@Id">@Label</label>
</div>

@code {
	[Parameter] public string? Label { get; set; }
	[Parameter] public string? WrapperDivCSS { get; set; }

	string Id { get; init; } = Guid.NewGuid().ToString();

	protected override bool TryParseValueFromString(string? value, out bool result, [NotNullWhen(false)] out string? validationErrorMessage)
	{
		bool parsed = bool.TryParse(value, out result);
		validationErrorMessage = parsed ? null : $"Failed to parse {value} as a boolean";
		return parsed;
	}
}

WrappedSwitch

@inherits WrappedCheckbox

<WrappedCheckbox Label="@Label" Value="@Value" ValueChanged="@ValueChanged" ValueExpression="@ValueExpression"
                 DisplayName="@DisplayName" WrapperDivCSS="form-switch" AdditionalAttributes="@AdditionalAttributes" />

@code {
}

Then replace the Index page with:

@page "/"

<PageTitle>Index</PageTitle>

<EditForm Model="EditItem">
	<WrappedSwitch Label="My Switch" @bind-Value="EditItem.MyProp"/>
</EditForm>

@code {
	public class EditModel
	{
		public bool MyProp { get; set; }
	}
	public EditModel EditItem { get; set; } = new();
}

Compile using both sdks and 203 will succeed while 302 fails

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

@ScarletKuro
Copy link

Probably related #8718

@almightyju almightyju changed the title Blazor wasm: RZ9991 build error when updating gfrom 7.0.203 to 7.0.302 sdk Blazor wasm: RZ9991 build error when updating from 7.0.203 to 7.0.302 sdk May 17, 2023
@mkArtakMSFT mkArtakMSFT transferred this issue from dotnet/aspnetcore May 17, 2023
@ghost ghost added the untriaged label May 17, 2023
@davidwengier davidwengier added the area-compiler Umbrella for all compiler issues label May 17, 2023
@fretje
Copy link

fretje commented May 18, 2023

I have the same issue (a component that's derived from a base component and the property to @bind to is in the base component).

This is blocking for us. I have to pin the sdk version to 7.0.203 to be able to build.

It's very strange behavior to say the least... the compiler is complaining, but the error is not visible in the code (with the red squiggle) like it normally is.

When I use @bind-Value (where the Value and ValueChanged properties are defined in the base class) like this;

<MyComponent @bind-Value="_value" />

I get:

error RZ9991: The attribute names could not be inferred from bind attribute 'bind-Value'. Bind attributes should be of the form 'bind' or 'bind-value' along with their corresponding optional parameters like 'bind-value:event', 'bind:format' etc.

And when I remove the @bind-Value:

<MyComponent />

I get another error:

error RZ10012: Found markup element with unexpected name 'MyComponent'. If this is intended to be a component, add a @using directive for its namespace.

I have tried adding a @using statement, or fully qualifying the namespace, but nothing helps.

@ArgoZhang
Copy link

ArgoZhang commented May 18, 2023

same issue. it work fine use 7.0.203

@jjonescz
Copy link
Member

Sorry you're hitting this. Seems like a regression fixed by #8614 but not yet in .NET 7. To confirm, try if your code works with .NET 8 SDK preview.

@jjonescz jjonescz added bug Something isn't working needs more info labels May 19, 2023
@ghost ghost removed the untriaged label May 19, 2023
@fretje
Copy link

fretje commented May 19, 2023

I found a way around it, by reading some of the other issues that have been posted about this.

I simply had to derive the "most" base component in the hierarchy chain from ComponentBase explicitly (in a the .razor.cs file), and this fixed the errors for us.

@sam-wheat
Copy link

I simply had to derive the "most" base component in the hierarchy chain from ComponentBase explicitly (in a the .razor.cs file), and this fixed the errors for us.

Does not work for me.

@bobwinners
Copy link

bobwinners commented May 31, 2023

I am having this same issue. Addng ComponentBase to the base class (partial) in a razor.cs file didnt help

@sam-wheat
Copy link

sam-wheat commented May 31, 2023

@bobwinners

Try splitting your BasePage into two physical files (.cs and .razor).

BasePage.cs should look like this:

public partial class BasePage : ComponentBase
{
    //...
}

This worked for me.

@bobwinners
Copy link

@sam-wheat I tried that and it didn't work. Thanks.

@ScarletKuro
Copy link

@bobwinners you should stick with previous SDK using global.json

{
  "sdk": {
    "version": "7.0.203"
  }
}

More info: https://learn.microsoft.com/en-us/dotnet/core/tools/global-json

@ghost ghost added the no recent activity label Jun 7, 2023
@ghost
Copy link

ghost commented Jun 7, 2023

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.

@jjonescz
Copy link
Member

jjonescz commented Jun 8, 2023

Closing as duplicate of #8718.

@jjonescz jjonescz closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-compiler Umbrella for all compiler issues bug Something isn't working needs more info no recent activity
Projects
None yet
Development

No branches or pull requests

9 participants