From 0eab91b859dd0a5cee2a73a2b47b093e24773ff8 Mon Sep 17 00:00:00 2001 From: Steven Giesel Date: Mon, 22 Dec 2025 19:05:12 +0100 Subject: [PATCH] fix: Add OverloadResolutionAttribute for Render method in .NET 9.0+ --- CHANGELOG.md | 4 ++++ src/bunit/BunitContext.cs | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d3a18812..d2b5b7d47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ All notable changes to **bUnit** will be documented in this file. The project ad ## [Unreleased] +### Added + +- `Render(RenderFragment)` is preferred via the `OverloadResolutionAttribute`. Reported by [@ScarletKuro](https://github.com/ScarletKuro) in #1800. Fixed by [@linkdotnet](https://github.com/linkdotnet). + ## [2.4.2] - 2025-12-21 ### Fixed diff --git a/src/bunit/BunitContext.cs b/src/bunit/BunitContext.cs index 948d44b15..cb3aea4d9 100644 --- a/src/bunit/BunitContext.cs +++ b/src/bunit/BunitContext.cs @@ -1,3 +1,6 @@ +#if NET9_0_OR_GREATER +using System.Runtime.CompilerServices; +#endif using Bunit.Extensions; using Bunit.Rendering; using Microsoft.Extensions.Logging; @@ -158,9 +161,12 @@ public virtual IRenderedComponent Render(ActionThe type of component to find in the render tree. /// The render fragment to render. /// The . +#if NET9_0_OR_GREATER + [OverloadResolutionPriority(1)] +#endif public virtual IRenderedComponent Render(RenderFragment renderFragment) where TComponent : IComponent - => this.RenderInsideRenderTree(renderFragment); + => RenderInsideRenderTree(renderFragment); /// /// Renders the and returns it as a .