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

FindComponent<T> Of derived component after a FindComponents<T> of base component cant cast #1691

Open
BlueDragon709 opened this issue Mar 20, 2025 · 1 comment

Comments

@BlueDragon709
Copy link

Describe the bug

When you search for a component that inherits from another component after you did a search of components of the base class the following exception is thrown:

Message: 
System.InvalidCastException : Unable to cast object of type 'Bunit.Rendering.RenderedComponent`1[BUnitRepro.Client.Tests.Components.WorkingComponent]' to type 'Bunit.IRenderedComponentBase`1[BUnitRepro.Client.Tests.Components.SubComponent]'.

  Stack Trace: 
TestRenderer.GetOrCreateRenderedComponent[TComponent](RenderTreeFrameDictionary framesCollection, Int32 componentId, TComponent component)
TestRenderer.<FindComponents>g__FindComponentsInRenderTree|43_0[TComponent](Int32 componentId, <>c__DisplayClass43_0`1&)
TestRenderer.FindComponents[TComponent](IRenderedFragmentBase parentComponent, Int32 resultLimit)
TestRenderer.FindComponents[TComponent](IRenderedFragmentBase parentComponent)
RenderedFragmentExtensions.FindComponents[TComponent](IRenderedFragment renderedFragment)
TestPageTests.FindBothInReverseInheritanceOrder() line 46
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Example:
Example can be found in the following git repo in the BUnitRepro.Client.Tests project
https://github.com/BlueDragon709/BUnitRepro/blob/master/BUnitRepro.Client.Tests/TestPageTests.cs

Expected behavior:
To be able to find a component by type in any order of calling FindComponent<T> or FindComponents<T> without crashing.

Version info:

  • bUnit version: 1.38.5
  • .NET Runtime and Blazor version: 9.0.3
  • OS type and version: Windows 10 Professional 22H2 - 19045.5487

Additional context:
None

@linkdotnet
Copy link
Collaborator

Sorry for the late answer @BlueDragon709
We will try to have a look this week into the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants