Calling garbage collector manually does not necessarily improve performanceCS-P1001Audit required: Switch to a better crypto algorithmCS-A1002Avoid empty finalizersCS-P1000Consider using `Environment.ProcessId` instead of `Process.GetCurrentProcess().Id`CS-P1002Async methods should not have a return type of `void`CS-R1005Non-Async methods with return type `Task/Task<T>` should not return `null`CS-R1006Use `Guid.Empty` to create an empty GUIDCS-R1007`ToString` method should never return `null`CS-R1011Potential memory leak inside `for` loop due to `stackalloc`CS-W1025Binary Formatter deserializes data in an insecure manner and should not be usedCS-S1006Audit required: Insecurely generated random numberCS-A1008Audit required: Cookie is transmitted over an insecure connectionCS-A1009Audit required: Cookie is accessible through a client-side scriptCS-A1010Use `double.IsNaN()` to check if a `double` is `NaN`CS-W1003Audit required: `enum` used for permissions is missing the `Flags` attributeCS-A1004Use the `is` operator to simplify type checkCS-R1049Filesystem related permissions specified are too broadCS-S1000Consider specifying the full path to the executable file when spawning processesCS-S1002Implementing custom crypto algorithms is not secureCS-S1005Empty interpolated stringCS-W1000Usage of deprecated `Thread`ing APIsCS-W1002`Equals` and `GetHashCode` must be overridden in pairCS-W1006Possible `IndexOutOfRangeException` whilst iteratingCS-W1007Comparison operator has same operands on both sidesCS-W1026Assignment expression found in place of conditionCS-W1032Using `throw ex` resets the Exception's stack traceCS-W1038Incorrectly formatted stringCS-W1024`ICloneable` does not define a spec for `Clone()` and hence should not be implementedCS-R1104Conditional branch has the same expression in both the branchesCS-W1073Incorrect variable being modified in nested loopsCS-W1074Casting a `object[]` to `string[]` will result in `CastException`CS-W1075Empty `lock` statements should be avoidedCS-W1076Empty `if` statements should be avoidedCS-W1077Getters and setters should be mutually synchronizedCS-W1078Operator implementation refers to itself and may cause recursive callsCS-W1079Use `ContainsKey()` to check if a key exists in a `Dictionary<T, K>`CS-P1016Result of the bitwise operation is same as its operandCS-R1089Anti-forgery token is ignored via `IgnoreAntiforgeryTokenAttribute`CS-A1011Consider using `Uri.EscapeDataString()` instead of `Uri.EscapeUriString()`CS-S1009Number of elements passed instead of buffer lengthCS-W1051Do not declare finalizers for types derived from `MemoryManager<T>`CS-W1052Pointer is being compared with `null`CS-W1063Unary operator is redundant due to its operandCS-R1090Insecure protocol specified for `ServicePointManager`CS-S1007Unary `is` expression can be simplifiedCS-R1094Consider using more appropriate overload `StringBuilder.Append(char)`CS-P1017Consider using `typeof(T).Assembly` to get currently executing assemblyCS-P1018Null conditional operator is made redundant by a dominant checkCS-R1087`ThreadStatic` attribute used on a field that has explicit valueCS-R1088Method is empty and effectively does nothingCS-R1093Security attribute is ineffective due to parent scope's attributeCS-S1008`GetType()` called on `System.Type`CS-W1064Consider moving to safer and recommended alternatives as the web APIs used are obsoleteCS-S1010Insecure SQL authentication specifiedCS-S1011Specified certificate validation callback is insecureCS-S1012Consider explicitly specifying the `XmlResolver` propertyCS-S1013Wildcard domains being listened to by `HttpListener`CS-S1014Incorrect block delimitationCS-S1015`DisableRequestSizeLimitAttribute` attribute used to disable request body's size limitsCS-S1016User input being processed directly without sanitizationCS-S1017Lock is obtained on a `public` `object`CS-W1046`GetHashCode()` relies on a mutable entityCS-W1048`enum` marked with `Flags` attribute is missing required initializationCS-W1049`StringBuilder` is initialized with an invalid argumentCS-W1050Value types should not be compared using `object.ReferenceEquals()`CS-W1053Result of `IsInstanceOfType()` may be unreliable as an incorrect argument is passedCS-W1065`Dictionary<T, K>` has duplicate key(s) in its initializerCS-W1054Argument passed to `Enum.HasFlag` should be same as the type on which it is being invokedCS-W1055Applying `ThreadStatic` to instance fields is redundantCS-W1056Do not expose unmanaged resourcesCS-W1057Exception thrown is obsolete and is no longer in use by the runtimeCS-W1058Throwing exceptions in `finally` block may affect resource cleanup and stack traceCS-W1060Classes and structs should be declared within a `namespace`CS-W1061A disposable entity is being returnedCS-W1062Missing implementation of members wrapped in an interface attributed with `DynamicInterfaceCastableImplementation`CS-W1066Incorrect `TaskCompletionSource` constructor invokedCS-W1067Result of a pure method is unusedCS-W1068Methods should pass optional parameters to the base implementationCS-W1071Comparing an entity's type against `typeof(Nullable<T>)` is unreliableCS-W1069Empty record achieves nothing and is likely a bad design patternCS-R1134Detected the use of arithmetic operation to construct a `DateTime` objectCS-W1080Values in an `enum` should be uniqueCS-W1088Result of an assignment expression is unusedCS-W1082Setter does not access `value`CS-W1083Division by zero results in `System.DivideByZeroException`CS-W1081Checking for overflow has been skippedCS-W1087Avoid inheriting outdated typesCS-R1115If-else chain has a duplicate conditionCS-W1084`static` field is hidden due to method's parameterCS-W1085Argument passed to `Equals()` is same as the object upon which this method is invokedCS-W1086Object is passed to a method that belongs to itselfCS-W1098Missing `Culture`-related information when parsing `Date` and `Time`-sCS-W1092`Length`-like property is compared against values which always evaluate to the same resultCS-W1090Found the usage of `DateTime.Now` that relies on system-specific informationCS-W1091`IEnumerable.Skip()` takes in number of elements to skip rather than the indexCS-W1093Acquiring `lock` on local variables is error-proneCS-W1094Object created is neither assigned to a variable nor passed as an argument but is dropped immediatelyCS-W1097Getter and setter should access the same fieldsCS-W1095Oddness test is broken for negative numbersCS-W1089Properties should not return arrays as they are not write protectedCS-W1096Parameters marked as `in`, `out` or `ref` should always be placed after all the required parametersCS-R1138`null` literal explicitly passed to `??` operatorCS-R1135Missing `Justification` value in `SuppressMessage` attributeCS-R1139Getters must not throw exceptionsCS-R1038Explicit trap of `NullReferenceException`CS-R1009Audit required: Call to potentially dangerous method `DangerousGetHandle`CS-A1001Audit: Consider using `System.URI` instead of `string`sCS-A1000Consider making `static readonly` fields `const`CS-P1003Do not overload the `==` operator to perform value equality checksCS-R1001Methods with `Pure` attribute should return a valueCS-R1002Methods with `DoesNotReturn` attribute should not return a valueCS-R1003Consider using `.TryParse` over `.Parse` when converting typesCS-R1004Exception caught is genericCS-R1008Accessor like method has return type `void`CS-R1013Use `string.IsNullOrEmpty` or `string.IsNullOrWhiteSpace` to check for empty stringsCS-R1014Exception thrown is genericCS-R1015Obsolete attribute should specify the messageCS-R1016Redundant call to `ToCharArray()` when iterating a stringCS-P1004Empty `default` label without a comment is redundantCS-R1022Method marked as `TestMethod` declared in a non-test classCS-W1013Consider having 1 `public` class per namespaceCS-R1035Consider using the appropriate overloaded method when searching for a single charCS-P1006Audit required: Instance of `NotImplementedException`CS-A1003Audit required: Warning disabled explicitlyCS-A1006Abrupt application exitCS-W1005`var` is redundant when combined with `out` and a discard patternCS-R1067Consider using `L` as a suffix for `long` rather than `l`CS-R1027Consider declaring only 1 `namespace` per fileCS-R1034Deprecated method being invokedCS-W1023Consider using the constants from the `Math` classCS-R1071Using negative array indices results in `IndexOutOfRangeException`CS-W1042Audit required: Test is ignoredCS-A1005Exceptions that are created must be usedCS-W1043Unreachable code detectedCS-W1016Avoid chaining of index lookup and `.Substring` methodCS-P1007Explicit mention of array type and/or size is redundant when array is initializedCS-R1045Empty initializer is redundantCS-R1063Type name contains only lower-cased ASCII charactersCS-W1036Consider using `.TryGetValue` to access elements in `Dictionary`CS-P1005Consider using the range operator `..` over `Substring`CS-R1037Consider rewriting chained `.OrderBy()` calls as `.ThenBy()`CS-P1008Use `Array.Empty<T>()` to efficiently create empty arraysCS-P1009Rewrite `virtual void Finalize()` as `~Destructor()`CS-P1010Use the method overload that accepts `Span<T>` instead of `T[]` when possible to reduce allocationsCS-P1011Use `StringComparison.OrdinalIgnoreCase` for case insensitive comparisonsCS-R1017Consider specifying the `CultureInfo` parameter when possibleCS-R1018Consider simplifying the element accessCS-R1019Consider returning an empty array instead of `null`CS-R1020Catch clauses that simply re`throw` Exceptions are redundantCS-R1021Pure methods cannot have return type `void`CS-R1023Overridden methods cannot simply call `base` class implementationCS-R1025`ref` / `out` parameters cannot be marked as `Optional`CS-R1026Explicit `default` constructors are redundantCS-R1028`TestMethods` must contain `Assert` statementsCS-R1029Usage of reserved keywords as variable identifierCS-R1030Consider simplifying the boolean comparison expression for concisionCS-R1031Consider inverting the predicate to simplify `!Any()` callCS-R1033Widening of `Exception` in the catch clauseCS-R1036`if` conditions can be mergedCS-R1039Consider collapsing the `null` checkCS-R1040Consider using `Any()` to check for emptinessCS-R1032Boolean expression with ternary operator can be simplifiedCS-R1042`null` check is redundant when used in combination with `is`CS-R1043Redundant `else` due to `return`CS-R1044Consider simplifying LINQ query by dropping explicit `.Where()` callCS-R1046Consider rewriting `Nullable<T>` as `T?`CS-R1047Consider rewriting `using` statement as `using` declarationCS-R1050Sorting expression can be simplifiedCS-R1051Explicitly inheriting `System.Object` and `int` for `class`es and `enum`s is redundantCS-R1052Classes implementing `IEquatable<T>` can be `sealed`CS-R1053Class implements `Equals` but not `IEquatable<T>`CS-R1054Consider rewriting null checks and casts using pattern matchingCS-R1056Comparing unconstrained generic parameter against `null` is bug-proneCS-R1057`sealed` modifier for a method in a `sealed` class is redundantCS-R1058Use `nameof` operator instead of explicitly spelling out the parameterCS-R1059Consider changing explicit getter and setter to auto-propertyCS-R1060Consider adding the `init` accessorCS-R1061Use File Scoped `namespace`s instead of typical `namespace`sCS-R1062Type can be dropped from the declaration's RHS when explicitly mentioned in the LHSCS-R1064`unsafe` block is redundant when placed in a method marked as `unsafe`CS-R1065`protected` field in a `sealed` class is redundantCS-R1066Lambda can be converted to a method groupCS-R1068Consider using the appropriate `Console.WriteLine()` overloadCS-R1070Discard patterns are redundant when used with the `is` operator and can be droppedCS-R1069You can drop the lower bound in a range expression if is zeroCS-R1072Insecure protocol specified in clear textCS-S1001Consider using SSL when dealing with SMTPCS-S1003Use `Path.GetTempFileName()` to generate unique filenames rather than relying on `DateTime`CS-S1004Custom `Exception`s should always be `public`CS-W1004Do not throw from critical methodsCS-W1008Switch statement is missing the `default` caseCS-W1009`IndexOf()` like methods operate on 0-based indexingCS-W1010Test method does not match the required signatureCS-W1011Use of Yoda expressionsCS-W1012Calling `Dispose` twice is UBCS-W1014`enum` with `Flags` attribute has invalid valuesCS-W1015Non-short circuit logic is likely a mistakeCS-W1017Use `DateTime.Compare()` to compare `DateTime`sCS-W1018Potential `NullReferenceException` when comparing against `null`CS-W1019`.ToString` on an array does not stringify its contentsCS-W1020Built-in entity shadowed by a declarationCS-W1021Variable is uninitializedCS-W1022Variable is assigned to itselfCS-W1027`null` is being assigned to an entity that is non-nullableCS-W1028Method has non-nullable return type but returns `null`CS-W1029Override `GetHashCode` and `Equals` if operators `==` and `!=` are overloadedCS-W1031Method marked as `extern` is missing relevant attributeCS-W1033Unused `goto` labelCS-W1034Method's generic parameter shadows class' generic parameterCS-W1035Program may not contain an `async` entrypoint when a `sync` entry point existsCS-W1037Entity marked for `export` is missing its implementationCS-W1039Constructors should initialize non-null fields when exitingCS-W1040`Stream.Read()` return value should always be checkedCS-W1041Consider using the `null-coalescing` operator to simplify the `null` checkCS-R1024Local declaration shadows class fields and propertiesCS-W1030Implementing `IComparable<T>` may be particularly usefulCS-R1106Consider reusing existing instances of `StringBuilder`CS-P1020Child and parent classes cannot share the same nameCS-R1103Variable declared when catching `Exception` is unusedCS-R1084`DefaultParameterValue` must be used instead of `DefaultValue` when `Optional` attribute is specifiedCS-W1045Consider simplifying lambda when its body has a single statementCS-R1085`if` statement can be rewritten using the ternary operatorCS-R1105Use `Environment.ProcessId` to fetch process ID instead of `Process.GetCurrentProcess().Id`CS-P1012Use `Environment.ProcessPath` to fetch process path instead of `Process.GetCurrentProcess().MainModule.FileName`CS-P1013Audit: Writing to a file that's in a publicly accessible directoryCS-A1012Audit required: Pointer arithmetic may point to incorrect memory locationCS-A1013Audit required: Path used in archive extraction maybe unsanitizedCS-A1014Use `Environment.CurrentManagedThreadId` to fetch the thread ID instead of `Thread.CurrentThread.ManagedThreadId`CS-P1014Empty `namespace`s are redundantCS-R1083Getters and setters with a single statement in their bodies can be simplifiedCS-R1095Passing an identity function to `Select()` is redundantCS-P1015Methods that deal with `async` should have their names suffixed with `Async`CS-R1073`DefaultParameterValue` attribute is redundant when parameter is not marked as `Optional`CS-R1074`Attribute` suffix is redundant when using an attributeCS-R1075Use underscores to make long numeric literals readableCS-R1076Rewrite `new System.Type[0]` as `Type.EmptyTypes`CS-R1077`abstract` classes with only `abstract` methods should be declared as `interface`sCS-R1078Replace `string.Compare()` with `string.Equals()`CS-R1079Reserving a member in an `enum` provides no benefitCS-R1080Consider using `ThrowIfCancellation()` where possibleCS-R1081Reserved `Exception` being thrownCS-R1082`CompilerGenerated` attribute should not be used within user defined codeCS-R1086Empty `finally` block is redundantCS-R1091Comparing against a value and assigning the same value is redundantCS-R1092`abstract` classes cannot contain `public` constructorsCS-R1096Consider using the `default` literal over `default(T)`CS-R1097Incorrectly placed typecheckCS-R1098Redundant call to base class' constructorCS-R1099Classes that inherit `EventArgs` should be named appropriatelyCS-R1102Lock is obtained on an entity that does not guarantee reliable mutual exclusionCS-W1044An `async` method should have at least a single `await`ableCS-W1047Method exposed by an unmanaged dynamic-link library (DLL) is `public`CS-W1059Field that was initialized inline is being overwritten in the constructorCS-W1072Do not prefix enum members with enum's nameCS-R1132Using the logical not operator to invert binary expressions can affect readabilityCS-R1108Missing implementation of `System.Exception`CS-R1109Drop record's body if it does not define any membersCS-R1130Use `.TryAdd` to safely add keys to a `Dictionary<K, V`>CS-R1123Consider replacing an `if` statement with just the condition if all it does is return a `bool` valueCS-R1126Consider reusing `record` objects that rely on `const` parametersCS-P1022Consider using `Clear()` to set the items in a `Span<T>` to their default valuesCS-P1023Consider using `not null` instead of an empty recursive pattern when checking for nullnessCS-R1120Consider using the equality operators when evaluating `bool?`CS-R1118Unusual data type specified for `enum`CS-P1021Consider dropping the parameter's name if it is same as the value when instantiating an anonymous objectCS-R1127Empty `else` statement is redundantCS-R1129Avoid nested ternary expressionsCS-R1114A `switch` statement having only a `default` case is redundantCS-R1124Consider using the indexer when adding a key to `Dictionary<K, V>`CS-R1119Duplicate `using` directives can be removedCS-R1122Switch statement is empty and effectively redundantCS-R1117Explicitly defined `case` labels are redundant if they fallthrough to `default` caseCS-R1107Consider using `string.Contains` instead of comparing the result of `string.IndexOf`CS-R1110Comment is empty and adds no contextCS-R1111Extension method is defined on `object` rather than a specific typeCS-R1112Missing space between `=` and subsequent operatorCS-R1113`default` case should always occur at last in a `switch` statementCS-R1121Comparing an instantiated object with `null` will always evaluate to `false`CS-R1125Using inefficient methods `Min()`/`Max()` on `SortedSet<T>`CS-P1025Fields initialized only in constructors can be made `readonly`CS-R1137Avoid multiple assignments in a single expressionCS-R1143`0` should be assigned to `None` in `enum`-s attributed with `Flags` attributeCS-R1144Consider passing `DateTimeKind` when possibleCS-W1099Use conditional access operator or pattern matching to safely access nullable valueCS-R1136Properties should not return collections' cloneCS-P1026Consider dropping redundant call to `HashSet<T>::Contains()`CS-R1142Using inefficient methods `First()`/`Last()` on `LinkedList<T>`CS-P1024Use of `TODO/FIXME` comment encounteredCS-D1000Consider discarding empty blocksCS-R1012Use aliases when using built-in typesCS-R1000Names of interfaces must begin with `I`CS-R1010Use brace initialization when creating a new object and setting its propertiesCS-R1048Redundant `new` keyword for arrays initialized in placeCS-R1055Nested switch statementsCS-W1001Convert complex expression to compound assignmentCS-R1100Custom attribute is missing `AttributeUsage` attributeCS-W1070`DefaultConnectionLimit` is set to a value that may degrade performanceCS-P1019Consider dropping attribute's parenthesisCS-R1101Numeric literal has incorrect groupingCS-R1131Deconstruct tuple expression to avoid repetitivenessCS-R1133Consider using `if`-`else` instead of a `switch` statement when having 2 or fewer casesCS-R1116`CancellationToken` parameter should always be placed last in the parameter listCS-R1141Function with cyclomatic complexity higher than thresholdCS-R1140
C#
Static Analysis, SAST, Code Coverage, Code Complexity
Sample Configuration
.deepsource.toml
version = 1
[[analyzers]]
name = "csharp"
Explore the docs for all configuration options.