Repository navigation
Description
Problem: VerificationResult.TryGetArgumentValue and GetArgumentValue throw NullReferenceException when the result's ErrorArguments is null, and several kinds of result returned by Verifier.Verify leave it null:
- Type verification results from
TypeVerifier, such asInterfaceMethodNotImplementedandInvalidBaseType. Their values go inArgsinstead (Verifier.cs:483-491at 6d39701). - Some results created from an exception while verifying a method or a type. One example is the "TypedReference not supported in .NET Core" result for
mkrefany(Verifier.cs:412-419,:452-469,:495-502,:536-543). The module-level results for aVerifierExceptionare another (:125-128,:165-168).
So a library caller that looks up an argument, such as Offset, on every result has to null-check ErrorArguments first. The ILVerify CLI is not affected: it reads arguments only from method results that have an error code and from metadata-reference results, and both always carry them.
Type verification results also leave Type unset. The results that VerifyType creates from exceptions set it (Verifier.cs:499, :520, :540). So with Verify(peReader, typeHandle, verifyMethods: true), a type result carries neither a Type nor a Method handle.
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
// Type verification result: the class does not implement IDisposable.Dispose.
.class public auto ansi beforefieldinit MissingDispose extends [System.Runtime]System.Object
implements [System.Runtime]System.IDisposable
{
}
.class public abstract auto ansi sealed beforefieldinit C extends [System.Runtime]System.Object
{
// Method result created from an exception (TypedReference is not supported by ILVerify).
.method public hidebysig static int32 MkRefAny() cil managed
{
.locals init (int32 V_0)
ldc.i4.7
stloc.0
ldloca.s V_0
mkrefany [System.Runtime]System.Int32
refanyval [System.Runtime]System.Int32
ldind.i4
ret
}
}Program.cs (the IResolver is a plain directory lookup and is omitted here):
var verifier = new Verifier(new DirectoryResolver(args[1]), new VerifierOptions());
verifier.SetSystemModuleName(new AssemblyNameInfo("System.Private.CoreLib"));
using var pe = new PEReader(File.OpenRead(args[0]));
MetadataReader md = pe.GetMetadataReader();
foreach (TypeDefinitionHandle type in md.TypeDefinitions)
{
foreach (VerificationResult result in verifier.Verify(pe, type, verifyMethods: true))
{
Console.Write($"{result.Code} \"{result.Message}\": ");
try
{
bool found = result.TryGetArgumentValue("Offset", out int offset);
Console.WriteLine($"TryGetArgumentValue(\"Offset\") = {found}, Type.IsNil = {result.Type.IsNil}");
}
catch (Exception e)
{
Console.WriteLine($"TryGetArgumentValue(\"Offset\") threw {e.GetType().Name}, Type.IsNil = {result.Type.IsNil}");
}
}
}With the Microsoft.ILVerification 10.0.12 package, and with ILVerification built from main at 6d39701, both on linux-x64 against Microsoft.NETCore.App 10.0.12:
InterfaceMethodNotImplemented "[MD]: Error: Class implements interface but not method, Class: '{0}' Interface: '{1}' Missing method: '{2}'.": TryGetArgumentValue("Offset") threw NullReferenceException, Type.IsNil = True
None "TypedReference not supported in .NET Core": TryGetArgumentValue("Offset") threw NullReferenceException, Type.IsNil = True
The expected result is that TryGetArgumentValue returns false for both, and that the type result's Type is the MissingDispose handle.
Cause
ErrorArguments has no initializer (VerificationResult.cs:18), and TryGetArgumentValue reads ErrorArguments.Length (VerificationResult.cs:30). Some result sites in Verifier.cs set ErrorArguments = Array.Empty<ErrorArgument>() (:305, :438, :521), and the ones listed above do not. The TypeVerifier callback in VerifyType sets Code, Message and Args, but not Type (Verifier.cs:485-490).
Regression? No. The property and the TypeVerifier callback 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 regression tests, 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 ILVerification argument lookup on results without arguments (dotn…