DropdownBase.SelectItem Invalid Cast Exception when using Value Property #662

Closed
opened 2026-01-29 17:41:10 +00:00 by claunia · 2 comments
Owner

Originally created by @groogiam on GitHub (Dec 6, 2022).

Describe the bug
The recent updates to optimize value selection appear to have broken the SelectItem method.

To Reproduce
Steps to reproduce the behavior:
See unit test code snippet using Radzen.Blazor 4.4.0

        [Fact]
        public async Task Dropdown_SelectItem_Method_Should_Not_Throw()
        {
            using var ctx = new TestContext();

            ctx.JSInterop.Mode = JSRuntimeMode.Loose;

            var component = DropDown<int>(ctx);

            var items = component.FindAll(".rz-dropdown-item");

            Assert.Equal(2, items.Count);

            //this throws
            await component.InvokeAsync(async () => await component.Instance.SelectItem(1));
        }

Alternatively link your repo with a sample project that can be run.

Expected behavior
Before the update SelectItem would take the value that you wanted set not an instance of the bound object type.

Originally created by @groogiam on GitHub (Dec 6, 2022). <!-- IMPORTANT: Read this first!!! 1. If you own a Radzen Professional or Еnterprise subscription you can report your issue or ask us a question via email at info@radzen.com. Radzen staff will reply within 24 hours (Professional) or 16 hours (Enterprise) 2. The Radzen staff guarantees a response to issues in this repo only to paid subscribers. 3. If you have a HOW TO question start a new forum thread in the Radzen Community forum: https://forum.radzen.com. Radzen staff will close issues that are HOWTO questions. 4. Please adhere to the issue template. Specify all the steps required to reproduce the issue or link a project which reproduces it easily (without requiring extra steps such as restoring a database). --> **Describe the bug** The recent updates to optimize value selection appear to have broken the SelectItem method. **To Reproduce** Steps to reproduce the behavior: See unit test code snippet using Radzen.Blazor 4.4.0 ```csharp [Fact] public async Task Dropdown_SelectItem_Method_Should_Not_Throw() { using var ctx = new TestContext(); ctx.JSInterop.Mode = JSRuntimeMode.Loose; var component = DropDown<int>(ctx); var items = component.FindAll(".rz-dropdown-item"); Assert.Equal(2, items.Count); //this throws await component.InvokeAsync(async () => await component.Instance.SelectItem(1)); } ``` Alternatively link your repo with a sample project that can be run. **Expected behavior** Before the update SelectItem would take the value that you wanted set not an instance of the bound object type.
Author
Owner

@enchev commented on GitHub (Dec 7, 2022):

Hi @groogiam,

This test failed with 4.4.0 as well:
image
image

@enchev commented on GitHub (Dec 7, 2022): Hi @groogiam, This test failed with 4.4.0 as well: ![image](https://user-images.githubusercontent.com/5804953/206113802-a365d290-5f68-4eb3-aa27-9f9b691442c9.png) ![image](https://user-images.githubusercontent.com/5804953/206113848-f7538603-43e2-44fc-92a5-2b1d4353ac84.png)
Author
Owner

@groogiam commented on GitHub (Dec 7, 2022):

Sorry I think my original post was not clear. This appears to be a regression from somewhere between 3.x and 4.x. It worked in 3.x but does not work in 4.4 and above. Looks like this might have been this commit b0baad56e7.

@groogiam commented on GitHub (Dec 7, 2022): Sorry I think my original post was not clear. This appears to be a regression from somewhere between 3.x and 4.x. It worked in 3.x but does not work in 4.4 and above. Looks like this might have been this commit https://github.com/radzenhq/radzen-blazor/commit/b0baad56e7845c917106390076e573c7a37ace4f.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#662