devlooped/moq · error · NotSupportedException

Use the new syntax, which allows you to pass the value in…

Error message

Use the new syntax, which allows you to pass the value in the expression itself, mock.VerifySet(m => m.Value = 25, failMessage); (thrown unconditionally via [Obsolete(..., true)])

What it means

This obsolete overload of Mock.VerifySet was compiled with an Error=true Obsolete attribute, so referencing it fails to compile; if somehow invoked at runtime it throws NotSupportedException. Moq replaced this (expression, value, failMessage) overload with the newer syntax where the assigned value is written directly inside the lambda, e.g. mock.VerifySet(m => m.Value == 25) / m => m.Value = 25 with the setter expression form.

Solutions

  1. Use the modern setter-expression syntax: mock.VerifySet(m => m.Value == 25, failMessage);
  2. Remove the separate value and failMessage parameters and fold the expected value into the lambda expression
  3. If the overload is referenced via reflection/dynamic, delete that call site and rewrite it against the current API

Example fix

// before
mock.VerifySet(m => m.Value, 25, "Value should be 25");
// after
mock.VerifySet(m => m.Value == 25, "Value should be 25");
Defensive patterns

Strategy: validation

Validate before calling

// Compile-time: avoid the obsolete overload entirely.
// Assert the expected assignment with the modern syntax:
mock.VerifySet(m => m.Value == 25, "Value should be 25");

Prevention

When it happens

Trigger: Calling mock.VerifySet(m => m.Value, 25, "fail") with the three-argument legacy overload on a Mock<T>. Using this overload produces a compiler error due to [Obsolete(..., true)].

Common situations: Upgrading Moq across major versions; old test code or snippets copied from pre-4.x documentation still using the value-passing VerifySet overload.

Understand the failure class

Background: "is deprecated and will be removed" — deprecation warnings for old API names, keywords, and options, and how to migrate before the removal release — this error's family across 29 libraries.

Related errors


AI-assisted analysis of devlooped/moq@89a5be629c (2026-09-16). Data as JSON: /api/errors/6bf5e084ad811e6a. Report an issue: GitHub.

Appendix: source

Thrown at src/Moq/Obsolete/Mock.Generic.Legacy.cs:109

        /// Obsolete.
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Obsolete("Use the new syntax, which allows you to pass the value in the expression itself, mock.VerifySet(m => m.Value = 25);", true)]
        public static void VerifySet<T, TProperty>(this Mock<T> mock, Expression<Func<T, TProperty>> expression, TProperty value)
            where T : class
        {
            throw new NotSupportedException();
        }

        /// <summary>
        /// Obsolete.
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Obsolete("Use the new syntax, which allows you to pass the value in the expression itself, mock.VerifySet(m => m.Value = 25, failMessage);", true)]
        public static void VerifySet<T, TProperty>(this Mock<T> mock, Expression<Func<T, TProperty>> expression, TProperty value, string failMessage)
            where T : class
        {
            throw new NotSupportedException();
        }
    }
}

View on GitHub (pinned to 89a5be629c)