Skip to content

Fix InvalidCastException in DefaultModelBindingContext#8334

Merged
NachoEchevarria merged 5 commits into
masterfrom
nacho/FixDefaultModelBindingContext
Mar 24, 2026
Merged

Fix InvalidCastException in DefaultModelBindingContext#8334
NachoEchevarria merged 5 commits into
masterfrom
nacho/FixDefaultModelBindingContext

Conversation

@NachoEchevarria

@NachoEchevarria NachoEchevarria commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

Summary of changes

Fix InvalidCastException in DefaultModelBindingContext_SetResult_Integration.OnMethodEnd by changing the ValueProvider field in the DefaultModelBindingContext DuckCopy struct from IList to object, and safe-casting to IList at the usage site.

Reason for change

Customers using custom IModelBinder implementations that set bindingContext.ValueProvider to a non-CompositeValueProvider (i.e., an IValueProvider that does not implement IList) trigger an InvalidCastException during DuckCopy:

Error : Exception occurred when calling the CallTarget integration continuation.
System.InvalidCastException
   at Datadog.Trace.ClrProfiler.AutoInstrumentation.AspNetCore.DefaultModelBindingContext_SetResult_Integration.OnMethodEnd[TTarget](TTarget instance, Exception exception, CallTargetState& state)
   at Microsoft.AspNetCore.Mvc.ModelBinding.DefaultModelBindingContext.set_Result(ModelBindingResult value)

In standard MVC usage, ValueProvider is always a CompositeValueProvider (which inherits from Collection<IValueProvider> and implements IList), so the DuckCopy Castclass IL instruction succeeds. However, when a custom model binder assigns a plain IValueProvider that does not implement IList, the cast fails. Additionally, TryDuckCast does not wrap CreateInstance in a try/catch, so the exception propagates uncaught.

Implementation details

Test coverage

Other details

@NachoEchevarria NachoEchevarria changed the title Fix DefaultModelBindingContext Fix InvalidCastException in DefaultModelBindingContext Mar 18, 2026
@pr-commenter

pr-commenter Bot commented Mar 18, 2026

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-03-23 15:24:39

Comparing candidate commit f312de4 in PR branch nacho/FixDefaultModelBindingContext with baseline commit 6f4edac in branch master.

Found 12 performance improvements and 7 performance regressions! Performance is the same for 254 metrics, 15 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

scenario:Benchmarks.Trace.AgentWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟥 execution_time [+87.015ms; +87.191ms] or [+76.942%; +77.098%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.AllCycleSimpleBody net6.0

  • 🟥 execution_time [+25.199ms; +30.187ms] or [+12.682%; +15.193%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody net6.0

  • 🟩 throughput [+147058.361op/s; +237330.623op/s] or [+5.058%; +8.163%]

scenario:Benchmarks.Trace.Asm.AppSecBodyBenchmark.ObjectExtractorSimpleBody netcoreapp3.1

  • 🟩 execution_time [-23.348ms; -16.972ms] or [-10.806%; -7.855%]

scenario:Benchmarks.Trace.Asm.AppSecWafBenchmark.RunWafRealisticBenchmarkWithAttack net6.0

  • 🟩 execution_time [-32.171µs; -17.564µs] or [-9.629%; -5.257%]
  • 🟩 throughput [+175.269op/s; +308.935op/s] or [+5.851%; +10.314%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net472

  • 🟥 execution_time [+13.246ms; +18.066ms] or [+6.840%; +9.329%]
  • 🟩 throughput [+142.255op/s; +167.461op/s] or [+14.341%; +16.882%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces net6.0

  • 🟩 execution_time [-17.713ms; -13.957ms] or [-9.315%; -7.340%]

scenario:Benchmarks.Trace.CIVisibilityProtocolWriterBenchmark.WriteAndFlushEnrichedTraces netcoreapp3.1

  • 🟩 execution_time [-76.605ms; -73.126ms] or [-35.615%; -33.998%]
  • 🟩 throughput [+241.957op/s; +278.450op/s] or [+18.069%; +20.795%]

scenario:Benchmarks.Trace.CharSliceBenchmark.OptimizedCharSliceWithPool net6.0

  • 🟥 execution_time [+88.048µs; +91.246µs] or [+8.567%; +8.878%]
  • 🟥 throughput [-79.481op/s; -76.654op/s] or [-8.168%; -7.878%]

scenario:Benchmarks.Trace.ILoggerBenchmark.EnrichedLog net6.0

  • 🟩 execution_time [-18.795ms; -14.829ms] or [-8.635%; -6.813%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore net6.0

  • 🟩 execution_time [-9.269ms; -8.112ms] or [-8.863%; -7.756%]

scenario:Benchmarks.Trace.SingleSpanAspNetCoreBenchmark.SingleSpanAspNetCore netcoreapp3.1

  • 🟥 throughput [-15883014.080op/s; -14444683.194op/s] or [-6.600%; -6.002%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope net6.0

  • 🟩 execution_time [-19.975ms; -14.007ms] or [-9.247%; -6.484%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishScope netcoreapp3.1

  • 🟩 execution_time [-16.719ms; -11.055ms] or [-7.865%; -5.200%]

scenario:Benchmarks.Trace.SpanBenchmark.StartFinishSpan netcoreapp3.1

  • 🟥 execution_time [+10.540ms; +15.840ms] or [+5.292%; +7.953%]

@dd-trace-dotnet-ci-bot

dd-trace-dotnet-ci-bot Bot commented Mar 18, 2026

Copy link
Copy Markdown

Execution-Time Benchmarks Report ⏱️

Execution-time results for samples comparing This PR (8334) and master.

⚠️ Potential regressions detected

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration192.99 ± (193.05 - 193.92) ms220.08 ± (219.39 - 220.95) ms+14.0%❌⬆️
.NET Framework 4.8 - Bailout
duration198.21 ± (198.20 - 199.08) ms224.15 ± (224.05 - 225.77) ms+13.1%❌⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1143.86 ± (1146.37 - 1153.34) ms1253.26 ± (1250.85 - 1258.80) ms+9.6%❌⬆️
Full Metrics Comparison

FakeDbCommand

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration69.17 ± (69.07 - 69.36) ms68.50 ± (68.51 - 68.76) ms-1.0%
.NET Framework 4.8 - Bailout
duration73.41 ± (73.29 - 73.59) ms72.63 ± (72.50 - 72.81) ms-1.1%
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1038.40 ± (1048.38 - 1059.66) ms1034.74 ± (1041.27 - 1050.93) ms-0.4%
.NET Core 3.1 - Baseline
process.internal_duration_ms21.77 ± (21.74 - 21.80) ms21.80 ± (21.78 - 21.83) ms+0.1%✅⬆️
process.time_to_main_ms79.33 ± (79.17 - 79.49) ms79.47 ± (79.32 - 79.61) ms+0.2%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.90 ± (10.90 - 10.91) MB10.91 ± (10.91 - 10.92) MB+0.1%✅⬆️
runtime.dotnet.threads.count12 ± (12 - 12)12 ± (12 - 12)+0.0%
.NET Core 3.1 - Bailout
process.internal_duration_ms21.72 ± (21.70 - 21.75) ms21.74 ± (21.72 - 21.77) ms+0.1%✅⬆️
process.time_to_main_ms80.56 ± (80.42 - 80.70) ms80.51 ± (80.36 - 80.66) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.95 ± (10.94 - 10.95) MB10.94 ± (10.94 - 10.95) MB-0.0%
runtime.dotnet.threads.count13 ± (13 - 13)13 ± (13 - 13)+0.0%
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms216.36 ± (215.37 - 217.35) ms217.29 ± (216.38 - 218.21) ms+0.4%✅⬆️
process.time_to_main_ms467.77 ± (467.30 - 468.24) ms469.28 ± (468.77 - 469.80) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed47.31 ± (47.29 - 47.34) MB47.32 ± (47.30 - 47.34) MB+0.0%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms20.51 ± (20.49 - 20.54) ms20.55 ± (20.52 - 20.58) ms+0.2%✅⬆️
process.time_to_main_ms68.70 ± (68.57 - 68.84) ms69.02 ± (68.88 - 69.17) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.61 ± (10.61 - 10.61) MB10.63 ± (10.62 - 10.63) MB+0.1%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 6 - Bailout
process.internal_duration_ms20.49 ± (20.47 - 20.51) ms20.52 ± (20.48 - 20.56) ms+0.1%✅⬆️
process.time_to_main_ms69.55 ± (69.44 - 69.66) ms70.07 ± (69.93 - 70.20) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed10.67 ± (10.66 - 10.67) MB10.74 ± (10.74 - 10.74) MB+0.7%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms200.96 ± (198.99 - 202.93) ms206.18 ± (204.01 - 208.36) ms+2.6%✅⬆️
process.time_to_main_ms468.99 ± (468.33 - 469.65) ms471.33 ± (470.68 - 471.98) ms+0.5%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed48.96 ± (48.89 - 49.02) MB49.00 ± (48.94 - 49.06) MB+0.1%✅⬆️
runtime.dotnet.threads.count29 ± (29 - 29)29 ± (29 - 29)+0.2%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms18.84 ± (18.81 - 18.88) ms18.86 ± (18.83 - 18.90) ms+0.1%✅⬆️
process.time_to_main_ms68.13 ± (67.99 - 68.27) ms68.58 ± (68.45 - 68.71) ms+0.7%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.67 ± (7.66 - 7.67) MB7.69 ± (7.68 - 7.69) MB+0.3%✅⬆️
runtime.dotnet.threads.count10 ± (10 - 10)10 ± (10 - 10)+0.0%
.NET 8 - Bailout
process.internal_duration_ms18.79 ± (18.76 - 18.82) ms18.81 ± (18.78 - 18.83) ms+0.1%✅⬆️
process.time_to_main_ms69.30 ± (69.18 - 69.43) ms69.53 ± (69.41 - 69.66) ms+0.3%✅⬆️
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed7.73 ± (7.73 - 7.74) MB7.75 ± (7.74 - 7.76) MB+0.2%✅⬆️
runtime.dotnet.threads.count11 ± (11 - 11)11 ± (11 - 11)+0.0%
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms157.58 ± (156.62 - 158.53) ms156.00 ± (155.09 - 156.90) ms-1.0%
process.time_to_main_ms448.33 ± (447.81 - 448.84) ms448.10 ± (447.56 - 448.64) ms-0.1%
runtime.dotnet.exceptions.count0 ± (0 - 0)0 ± (0 - 0)+0.0%
runtime.dotnet.mem.committed36.54 ± (36.52 - 36.56) MB36.55 ± (36.53 - 36.57) MB+0.0%✅⬆️
runtime.dotnet.threads.count28 ± (28 - 28)28 ± (28 - 28)+0.0%✅⬆️

HttpMessageHandler

Metric Master (Mean ± 95% CI) Current (Mean ± 95% CI) Change Status
.NET Framework 4.8 - Baseline
duration192.99 ± (193.05 - 193.92) ms220.08 ± (219.39 - 220.95) ms+14.0%❌⬆️
.NET Framework 4.8 - Bailout
duration198.21 ± (198.20 - 199.08) ms224.15 ± (224.05 - 225.77) ms+13.1%❌⬆️
.NET Framework 4.8 - CallTarget+Inlining+NGEN
duration1143.86 ± (1146.37 - 1153.34) ms1253.26 ± (1250.85 - 1258.80) ms+9.6%❌⬆️
.NET Core 3.1 - Baseline
process.internal_duration_ms187.52 ± (187.18 - 187.86) ms220.50 ± (219.45 - 221.55) ms+17.6%✅⬆️
process.time_to_main_ms80.41 ± (80.21 - 80.61) ms92.88 ± (92.53 - 93.22) ms+15.5%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.15 ± (16.12 - 16.17) MB15.80 ± (15.78 - 15.81) MB-2.2%
runtime.dotnet.threads.count20 ± (20 - 20)20 ± (20 - 20)+1.9%✅⬆️
.NET Core 3.1 - Bailout
process.internal_duration_ms186.79 ± (186.49 - 187.08) ms217.87 ± (217.06 - 218.68) ms+16.6%✅⬆️
process.time_to_main_ms81.74 ± (81.61 - 81.87) ms93.87 ± (93.60 - 94.14) ms+14.8%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed16.21 ± (16.18 - 16.25) MB15.88 ± (15.86 - 15.90) MB-2.0%
runtime.dotnet.threads.count21 ± (20 - 21)21 ± (21 - 21)+2.0%✅⬆️
.NET Core 3.1 - CallTarget+Inlining+NGEN
process.internal_duration_ms396.34 ± (394.50 - 398.18) ms427.53 ± (425.54 - 429.52) ms+7.9%✅⬆️
process.time_to_main_ms472.64 ± (472.13 - 473.15) ms528.06 ± (526.72 - 529.40) ms+11.7%✅⬆️
runtime.dotnet.exceptions.count3 ± (3 - 3)3 ± (3 - 3)+0.0%
runtime.dotnet.mem.committed57.66 ± (57.50 - 57.82) MB58.26 ± (58.22 - 58.29) MB+1.0%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.4%✅⬆️
.NET 6 - Baseline
process.internal_duration_ms192.44 ± (192.01 - 192.87) ms221.08 ± (220.37 - 221.79) ms+14.9%✅⬆️
process.time_to_main_ms69.96 ± (69.78 - 70.14) ms80.07 ± (79.83 - 80.31) ms+14.4%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.05 ± (15.92 - 16.19) MB16.15 ± (16.13 - 16.16) MB+0.6%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)20 ± (20 - 20)+4.2%✅⬆️
.NET 6 - Bailout
process.internal_duration_ms192.22 ± (191.76 - 192.68) ms223.48 ± (222.54 - 224.42) ms+16.3%✅⬆️
process.time_to_main_ms71.09 ± (70.93 - 71.25) ms81.66 ± (81.41 - 81.91) ms+14.9%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed16.05 ± (15.90 - 16.21) MB16.15 ± (16.13 - 16.17) MB+0.6%✅⬆️
runtime.dotnet.threads.count19 ± (19 - 19)20 ± (20 - 21)+6.5%✅⬆️
.NET 6 - CallTarget+Inlining+NGEN
process.internal_duration_ms428.77 ± (427.15 - 430.40) ms498.67 ± (491.85 - 505.49) ms+16.3%✅⬆️
process.time_to_main_ms473.98 ± (473.15 - 474.81) ms526.41 ± (525.04 - 527.77) ms+11.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed60.25 ± (60.16 - 60.35) MB58.95 ± (58.86 - 59.04) MB-2.2%
runtime.dotnet.threads.count30 ± (30 - 30)31 ± (31 - 31)+1.6%✅⬆️
.NET 8 - Baseline
process.internal_duration_ms190.28 ± (189.90 - 190.67) ms226.46 ± (225.17 - 227.75) ms+19.0%✅⬆️
process.time_to_main_ms69.48 ± (69.29 - 69.66) ms79.41 ± (79.16 - 79.67) ms+14.3%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.77 ± (11.74 - 11.80) MB11.41 ± (11.39 - 11.43) MB-3.0%
runtime.dotnet.threads.count18 ± (18 - 18)19 ± (19 - 19)+4.5%✅⬆️
.NET 8 - Bailout
process.internal_duration_ms189.20 ± (188.89 - 189.50) ms221.34 ± (220.35 - 222.34) ms+17.0%✅⬆️
process.time_to_main_ms70.42 ± (70.30 - 70.54) ms80.28 ± (80.04 - 80.52) ms+14.0%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed11.76 ± (11.69 - 11.83) MB11.51 ± (11.50 - 11.53) MB-2.1%
runtime.dotnet.threads.count19 ± (18 - 19)20 ± (20 - 20)+7.1%✅⬆️
.NET 8 - CallTarget+Inlining+NGEN
process.internal_duration_ms352.63 ± (351.38 - 353.88) ms466.60 ± (460.44 - 472.76) ms+32.3%✅⬆️
process.time_to_main_ms451.07 ± (450.50 - 451.63) ms496.46 ± (495.61 - 497.31) ms+10.1%✅⬆️
runtime.dotnet.exceptions.count4 ± (4 - 4)4 ± (4 - 4)+0.0%
runtime.dotnet.mem.committed48.54 ± (48.51 - 48.57) MB50.21 ± (50.11 - 50.31) MB+3.4%✅⬆️
runtime.dotnet.threads.count30 ± (30 - 30)30 ± (30 - 30)+0.3%✅⬆️
Comparison explanation

Execution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:

  • Welch test with statistical test for significance of 5%
  • Only results indicating a difference greater than 5% and 5 ms are considered.

Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard.

Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph).

Duration charts
FakeDbCommand (.NET Framework 4.8)
gantt
    title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (69ms)  : 67, 70
    master - mean (69ms)  : 67, 71

    section Bailout
    This PR (8334) - mean (73ms)  : 71, 74
    master - mean (73ms)  : 72, 75

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (1,046ms)  : 978, 1115
    master - mean (1,054ms)  : 968, 1140

Loading
FakeDbCommand (.NET Core 3.1)
gantt
    title Execution time (ms) FakeDbCommand (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (107ms)  : 104, 110
    master - mean (107ms)  : 103, 110

    section Bailout
    This PR (8334) - mean (108ms)  : 106, 110
    master - mean (108ms)  : 106, 110

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (723ms)  : 701, 746
    master - mean (722ms)  : 699, 744

Loading
FakeDbCommand (.NET 6)
gantt
    title Execution time (ms) FakeDbCommand (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (95ms)  : 92, 97
    master - mean (94ms)  : 91, 98

    section Bailout
    This PR (8334) - mean (96ms)  : 94, 98
    master - mean (95ms)  : 93, 97

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (706ms)  : 662, 750
    master - mean (699ms)  : 648, 749

Loading
FakeDbCommand (.NET 8)
gantt
    title Execution time (ms) FakeDbCommand (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (94ms)  : 92, 97
    master - mean (94ms)  : 91, 96

    section Bailout
    This PR (8334) - mean (95ms)  : 93, 97
    master - mean (95ms)  : 93, 97

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (633ms)  : 610, 656
    master - mean (637ms)  : 615, 658

Loading
HttpMessageHandler (.NET Framework 4.8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (220ms)  : 209, 231
    master - mean (193ms)  : 189, 198

    section Bailout
    This PR (8334) - mean (225ms)  : crit, 212, 237
    master - mean (199ms)  : 193, 204

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (1,255ms)  : crit, 1196, 1314
    master - mean (1,150ms)  : 1100, 1200

Loading
HttpMessageHandler (.NET Core 3.1)
gantt
    title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (324ms)  : 305, 343
    master - mean (276ms)  : 272, 281

    section Bailout
    This PR (8334) - mean (322ms)  : crit, 303, 342
    master - mean (277ms)  : 273, 281

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (997ms)  : crit, 953, 1041
    master - mean (900ms)  : 865, 936

Loading
HttpMessageHandler (.NET 6)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 6)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (311ms)  : 298, 323
    master - mean (271ms)  : 264, 277

    section Bailout
    This PR (8334) - mean (315ms)  : crit, 294, 336
    master - mean (272ms)  : 266, 277

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (1,071ms)  : crit, 950, 1191
    master - mean (936ms)  : 912, 960

Loading
HttpMessageHandler (.NET 8)
gantt
    title Execution time (ms) HttpMessageHandler (.NET 8)
    dateFormat  x
    axisFormat %Q
    todayMarker off
    section Baseline
    This PR (8334) - mean (318ms)  : 293, 342
    master - mean (269ms)  : 264, 275

    section Bailout
    This PR (8334) - mean (313ms)  : crit, 296, 330
    master - mean (269ms)  : 265, 273

    section CallTarget+Inlining+NGEN
    This PR (8334) - mean (999ms)  : crit, 908, 1090
    master - mean (835ms)  : 804, 866

Loading

@NachoEchevarria
NachoEchevarria marked this pull request as ready for review March 23, 2026 09:59
@NachoEchevarria
NachoEchevarria requested review from a team as code owners March 23, 2026 09:59

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, thanks, though I think it creates a gap we should try to close best as we can

}
}
else
else if (defaultModelBindingContext.ValueProvider is IList valueProviderList)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only trouble here is that this adds a third branch, where we have a ValueProvider that is not an IList (which could be common), so I think in that case, we still need to run the body of this loop 🤔

In other words:

  • Keep this loop
  • Add another else, e.g. else if (defaultModelBindingContext.ValueProvider.TryDuckCast(out BindingSourceValueProvider prov)) etc
  • Refactor to reduce the duplication 😄

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I have added this case and refactored the code. Thanks!

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@NachoEchevarria
NachoEchevarria merged commit 390e11e into master Mar 24, 2026
140 checks passed
@NachoEchevarria
NachoEchevarria deleted the nacho/FixDefaultModelBindingContext branch March 24, 2026 10:30
@github-actions github-actions Bot added this to the vNext-v3 milestone Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants