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); (thrown unconditionally via [Obsolete(..., true)])

What it means

This legacy Mock.VerifySet<T,TProperty> extension (value passed as a separate argument) is marked [Obsolete(..., true)] and always throws NotSupportedException. Verification of property setters now uses the expression-embedded value syntax mock.VerifySet(m => m.Value = 25).

Solutions

  1. Rewrite as mock.VerifySet(m => m.Value = 25).
  2. Combine with Times for counts: mock.VerifySet(m => m.Value = 25, Times.Once).
  3. Use It.Is<TProperty> in the expression for range/condition checks instead of the old value parameter.

Example fix

// before
Mock.VerifySet(mock, f => f.Value, 25);
// after
mock.VerifySet(f => f.Value = 25);
Defensive patterns

Strategy: try-catch

Try / catch

try { Mock.VerifySet(mock, f => f.Value, 25); } catch (NotSupportedException) { mock.VerifySet(f => f.Value = 25); }

Prevention

When it happens

Trigger: Mock.VerifySet(mock, m => m.Value, 25) — invoking the static extension in src/Moq/Obsolete/Mock.Generic.Legacy.cs:98 that takes the expected value as a parameter.

Common situations: Migrating pre-4.0 Moq verification code; bulk-updated test suites where VerifySet call sites were missed during upgrade because they still compiled via the extension.

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/ecec849b87b74bac. Report an issue: GitHub.

Appendix: source

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

        /// Obsolete.
        /// </summary>
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Obsolete("The new syntax allows you to pass the value in the expression itself, like f => f.Value = 25.", true)]
        public static ISetupSetter<T, TProperty> SetupSet<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);", 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)