dotnet/wpf · error · ArgumentOutOfRangeException
Specified argument was out of the range of valid values.
Error message
Specified argument was out of the range of valid values.
What it means
The SignatureVerificationEventArgs constructor validates that the VerifyResult passed is one of the defined enum values (Success through NotSigned). Passing any other integer cast to VerifyResult throws ArgumentOutOfRangeException for the 'result' parameter.
Solutions
- Only pass values obtained from VerifySignatures/Signature.Verify — never cast raw integers to VerifyResult
- Clamp or validate the integer against Enum.IsDefined(typeof(VerifyResult), value) before constructing the event args
- If persisting results, store and rehydrate them through the enum's named members
Example fix
// before
var args = new SignatureVerificationEventArgs(sig, (VerifyResult)99); // throws
// after
if (Enum.IsDefined(typeof(VerifyResult), rawResult))
var args = new SignatureVerificationEventArgs(sig, (VerifyResult)rawResult); Defensive patterns
Strategy: validation
Validate before calling
if (!Enum.IsDefined(typeof(VerifyResult), rawResult))
throw new ArgumentOutOfRangeException(nameof(rawResult));
var args = new SignatureVerificationEventArgs(signature, (VerifyResult)rawResult); Type guard
bool IsValidVerifyResult(object v) => v is VerifyResult r && r is >= VerifyResult.Success and <= VerifyResult.NotSigned;
Try / catch
try { var args = new SignatureVerificationEventArgs(sig, result); }
catch (ArgumentOutOfRangeException) { /* result value not a valid VerifyResult */ } Prevention
- Only pass VerifyResult values returned by the verify APIs
- Never cast unvalidated integers to VerifyResult
- Persist verification results as enum names, not raw integers
When it happens
Trigger: Constructing SignatureVerificationEventArgs directly (or via code paths that do) with a VerifyResult value outside the enum's defined range, e.g. (VerifyResult)99.
Common situations: Custom verification wrappers building event args manually; deserializing a stored VerifyResult integer that no longer matches the enum; unit tests passing arbitrary values.
Related errors
- ' ' is not a valid value for ' '.
- ArgumentOutOfRangeException(authentication)
- ArgumentOutOfRangeException(userActivationMode)
- autoComplete
- captureMode
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/b2bfd459139decae.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs:87
get
{
return _result;
}
}
//------------------------------------------------------
//
// Internal Members
//
//------------------------------------------------------
internal SignatureVerificationEventArgs(PackageDigitalSignature signature,
VerifyResult result)
{
// verify arguments
ArgumentNullException.ThrowIfNull(signature);
if (result < VerifyResult.Success || result > VerifyResult.NotSigned)
throw new System.ArgumentOutOfRangeException(nameof(result));
_signature = signature;
_result = result;
}
//------------------------------------------------------
//
// Private Members
//
//------------------------------------------------------
private PackageDigitalSignature _signature;
private VerifyResult _result;
}
/// <summary>
/// PackageDigitalSignatureManager
/// </summary>
public sealed class PackageDigitalSignatureManagerView on GitHub (pinned to 81131a70a4)