Last Updated:
14 Oct 2026 08:48
by Dan Avni
InvalidProgramException when JustMock instruments .NET 9 FrozenSet lookup with ReadOnlySpan<char>
Description: With the JustMock profiler attached, a .NET 9 FrozenSet alternate lookup using ReadOnlySpan<char> throws InvalidProgramException. The exception occurs in a generic FindItemIndex<TAlternate> method that permits ref-struct type arguments. The method is not mocked, and the same code succeeds when the profiler is disabled.
Suspected root cause: The profiler’s interception bridge marshals arguments through object[]. Source inspection indicates that generic parameters can reach a boxing path without accounting for the allows ref struct constraint. When TAlternate is ReadOnlySpan<char>, the rewritten IL attempts to box a ref struct, which is not valid. The CLR then rejects the instrumented method.
Expected behavior: Methods that JustMock is not asked to mock should retain valid IL and execute normally with the profiler attached.