Repository navigation
Description
Problem: when the target of a callvirt is a static method, ILVerify throws NullReferenceException instead of reporting a verification error. The CLI then stops at that method, so the remaining methods and the type-verification pass are not processed and their errors are never reported.
The expected result is a CallVirtOnStatic verification error. The error code and its message ("callvirt on static.") already exist, but the error is never returned.
Repro
Repro.il:
.assembly extern System.Runtime { .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) .ver 10:0:0:0 }
.assembly Repro { .ver 1:0:0:0 }
.module Repro.dll
.class public abstract auto ansi sealed beforefieldinit C extends [System.Runtime]System.Object
{
.method public hidebysig static void Target(int32 x) cil managed
{
ret
}
.method public hidebysig static void CallvirtStatic() cil managed
{
// callvirt void C::Target(int32). ilasm adds 'instance' to the signature of a
// callvirt target written by name, so the static MethodDef is named by token.
ldc.i4.1
callvirt mdtoken(0x06000001)
ret
}
.method public hidebysig static void Later() cil managed
{
// A real error in a later method: a value is left on the stack at a void return.
ldc.i4.0
ret
}
}$ ilasm -dll -output=Repro.dll Repro.il # Microsoft.NETCore.ILAsm 12.0.0-alpha.1.26471.108
$ ilverify Repro.dll -r '<Microsoft.NETCore.App 10.0.12>/*.dll' -s System.Private.CoreLib
Error: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Internal.IL.ILImporter.ImportCall(ILOpcode opcode, Int32 token) in src/coreclr/tools/ILVerification/ILImporter.Verify.cs:line 1611
at Internal.IL.ILImporter.ImportBasicBlock(BasicBlock basicBlock) in src/coreclr/tools/Common/TypeSystem/IL/ILImporter.cs:line 610
at Internal.IL.ILImporter.ImportBasicBlocks() in src/coreclr/tools/Common/TypeSystem/IL/ILImporter.cs:line 323
at Internal.IL.ILImporter.Verify() in src/coreclr/tools/ILVerification/ILImporter.Verify.cs:line 236
at ILVerify.Verifier.VerifyMethod(...) in src/coreclr/tools/ILVerification/Verifier.cs:line 406
...
The CLI exits with code 1, and the ReturnVoid error in Later is not reported.
Reproduced with ILVerify built from main at 6d39701 on linux-x64, and with the Microsoft.ILVerification 10.0.12 package, which throws the same exception from ImportCall.
ilasm turns callvirt void C::Target(int32) into an instance MemberRef that does not resolve, so the repro writes the MethodDef token directly. An emitter that references the method by its MethodDef token produces the same IL.
Cause
In ImportCall (ILImporter.Verify.cs:1606-1611 at 6d39701), methodType is null when the target's signature is static. The callvirt branch runs Check(methodType != null, VerifierError.CallVirtOnStatic), which records the error and continues, and the next line, Check(!methodType.IsValueType, VerifierError.CallVirtOnValueType), dereferences methodType.
Impact
VerifyMethod catches a fixed set of exception types (Verifier.cs:408-448), and NullReferenceException is not one of them, so the exception escapes Verifier.Verify.
The runtime does not accept this shape either. The same method body, JIT-compiled with RuntimeHelpers.PrepareMethod, fails with MissingMethodException on .NET 10.0.12 (linux-x64).
Configuration
- ILVerify: built from
mainat 6d39701 with the repo SDK (11.0.100-rc.1.26420.103); also theMicrosoft.ILVerification10.0.12 package. - Host: linux-x64 (Ubuntu 26.04).
- References: Microsoft.NETCore.App 10.0.12.
Regression? No. Both checks are unchanged since ILVerify moved into this repo (9a22600, 2020), and release/10.0 and release/11.0 have the same code.
I have a fix with a regression test, and will open a PR.
Note
This issue was prepared with AI assistance (Anthropic Claude and OpenAI Codex), under my direction. I reviewed it before posting.
Activity
dotnet-policy-service commentedon Oct 14, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
See info in area-owners.md if you want to be subscribed.
Fix ILVerify crash on callvirt to a static method (#135772)