Skip to content

Blazor 'System.Reflection.AmbiguousMatchException' on .NET 8 #52755

@thanuja89

Description

@thanuja89

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When we update our blazor webassembly app, we noticed that we are getting "System.Reflection.AmbiguousMatchException: Ambiguous match found for" for properties if the code blocks (code-behind) contained two properties with the similar names which differs in case only (for eg: Model and model).

Expected Behavior

No error thould be thrown and the correct property should be used.

Steps To Reproduce

This is a demo of the bug. Go to counter page and you'll get an error.

https://github.com/thanuja89/BlazorBugRepo

Exceptions (if any)

System.Reflection.AmbiguousMatchException: Ambiguous match found for 'BlazorAppBug.Client.Pages.Counter ModelModel Model'.
at System.RuntimeType.GetField(String name, BindingFlags bindingAttr)
at System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName)
at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.g__CreateAccessor|14_0(ValueTuple2 arg) at System.Collections.Concurrent.ConcurrentDictionary2[[System.ValueTuple2[[System.Type, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(ValueTuple2 key, Func2 valueFactory)
at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.GetModelFromMemberAccess(MemberExpression member, ConcurrentDictionary2 cache) at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.ParseAccessor[String](Expression1 accessor, Object& model, String& fieldName)
at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create[String](Expression1 accessor) at Microsoft.AspNetCore.Components.Forms.InputBase1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].SetParametersAsync(ParameterView parameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)
crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Ambiguous match found for 'BlazorAppBug.Client.Pages.Counter ModelModel Model'.
System.Reflection.AmbiguousMatchException: Ambiguous match found for 'BlazorAppBug.Client.Pages.Counter ModelModel Model'.
at System.RuntimeType.GetField(String name, BindingFlags bindingAttr)
at System.Linq.Expressions.Expression.PropertyOrField(Expression expression, String propertyOrFieldName)
at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.g__CreateAccessor|14_0(ValueTuple2 arg) at System.Collections.Concurrent.ConcurrentDictionary2[[System.ValueTuple2[[System.Type, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Func2[[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].GetOrAdd(ValueTuple2 key, Func2 valueFactory)
at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.GetModelFromMemberAccess(MemberExpression member, ConcurrentDictionary2 cache) at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.ParseAccessor[String](Expression1 accessor, Object& model, String& fieldName)
at Microsoft.AspNetCore.Components.Forms.FieldIdentifier.Create[String](Expression1 accessor) at Microsoft.AspNetCore.Components.Forms.ValidationMessage1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].OnParametersSet()
at Microsoft.AspNetCore.Components.ComponentBase.CallOnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

.NET Version

.NET 8

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions