You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ILVerify does not detect disallowed boxing of byref-like types #132954
I'm working on adding ref struct support to the Boo compiler, and as expected it's producing some invalid IL until I get the details worked out. But one of the early tests is failing, throwing System.InvalidProgramException: Common Language Runtime detected an invalid program at runtime, while passing ILVerify with no errors.
Reproduction Steps
Open the attached zip file. It contains the testcase, and its ILDASM disassembly for convenience. The disassembly has one non-trivial method, Main.
This is the original code. It should do exactly what it looks like it does:
import System
var span = "Hello, World!".AsSpan()
for letter in span:
Console.Write(letter)
Console.WriteLine()
The generated assembly throws InvalidProgramException at runtime, but ILVerify gives it a clean bill of health, so it's not clear what I need to fix in the codegen.
Expected behavior
ILVerify should correctly diagnose invalid assemblies.
changed the title [-]Unexplained error loading experimental assembly.[/-][+]ILVerify does not detect disallowed boxing of byref-like types[/+]on Aug 30, 2026
@jkotas ...or not. After iterating on this a little bit, I get a new version that now throws System.ExecutionEngineException. ILVerify still gives it a clean bill of health, and strangely, I don't see any substantial difference between this and the IL output of Roslyn here. Any idea what's going wrong?
@jkotas What I meant by that was, whatever mechanism detected that the other error was "an invalid program" before it begins to execute and causes an execution engine exception, which I assume is part of the JIT, did not catch this one.
Activity
dotnet-policy-service commentedon Aug 30, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
jkotas commentedon Aug 30, 2026
box valuetype [System.Private.CoreLib]System.ReadOnlySpan1/Enumerator` is the problem. Boxing of byref-like types is not allowed.dotnet-policy-service commentedon Aug 30, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.
[-]Unexplained error loading experimental assembly.[/-][+]ILVerify does not detect disallowed boxing of byref-like types[/+]masonwheeler commentedon Aug 30, 2026
Thanks! That'll get me unblocked.
masonwheeler commentedon Aug 30, 2026
@jkotas ...or not. After iterating on this a little bit, I get a new version that now throws
System.ExecutionEngineException. ILVerify still gives it a clean bill of health, and strangely, I don't see any substantial difference between this and the IL output of Roslyn here. Any idea what's going wrong?New version:
EgorBo commentedon Aug 30, 2026
your IL should be:
masonwheeler commentedon Aug 30, 2026
@EgorBo And now it works. Thanks!
So now we have two ref-related problems that ILVerify misses, one of which the JIT also doesn't appear to recognize.
Span enumerator support
jkotas commentedon Aug 30, 2026
JIT is not expected to validate the IL.
masonwheeler commentedon Aug 30, 2026
@jkotas What I meant by that was, whatever mechanism detected that the other error was "an invalid program" before it begins to execute and causes an execution engine exception, which I assume is part of the JIT, did not catch this one.
Span enumerator support
ilverify: report boxing of byref-like types (#135924)