Search Results for

    Show / Hide Table of Contents

    NUnit2024

    Wrong actual type used with String Constraint

    Topic Value
    Id NUnit2024
    Severity Error
    Enabled True
    Category Assertion
    Code StringConstraintWrongActualTypeAnalyzer

    Description

    The type of the actual argument is not a string and hence cannot be used with a String Constraint.

    Motivation

    Assertions with string constraints and non-string actual value will fail with error.

    How to fix violations

    Fix actual value or use appropriate constraint.

    Configure severity

    Via ruleset file

    Configure the severity per project, for more info see MSDN.

    Via .editorconfig file

    # NUnit2024: Wrong actual type used with String Constraint
    dotnet_diagnostic.NUnit2024.severity = chosenSeverity
    

    where chosenSeverity can be one of none, silent, suggestion, warning, or error.

    Via #pragma directive

    #pragma warning disable NUnit2024 // Wrong actual type used with String Constraint
    Code violating the rule here
    #pragma warning restore NUnit2024 // Wrong actual type used with String Constraint
    

    Or put this at the top of the file to disable all instances.

    #pragma warning disable NUnit2024 // Wrong actual type used with String Constraint
    

    Via attribute [SuppressMessage]

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
        "NUnit2024:Wrong actual type used with String Constraint",
        Justification = "Reason...")]
    
    • Edit this page
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0