Skip to content

ILVerification: TryGetArgumentValue throws NullReferenceException on results that have no ErrorArguments #135773

Closed

Description

@pcshrosbree

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 as InterfaceMethodNotImplemented and InvalidBaseType. Their values go in Args instead (Verifier.cs:483-491 at 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 a VerifierException are 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

  1. added
    untriaged
    on Oct 14, 2026
  2. added
    area-Tools-ILVerification
    on Oct 14, 2026
  3. dotnet-policy-service commented on Oct 14, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @dotnet/jit-contrib
    See info in area-owners.md if you want to be subscribed.

  4. removed
    untriaged
    on Oct 15, 2026
  5. added a commit that references this issue on Oct 15, 2026
    d7adeaa
  6. locked and limited conversation to collaborators on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILVerification

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions