ReSharper 2022.1 Help

Code Inspection: Cannot resolve symbol in text argument

This code inspection validates identifier names used in string literals according to various .NET Framework contracts — for example, constructor parameters of System.Diagnostics.DebuggerDisplayAttribute or of System.ArgumentException and its inheritors.

Let's take a look at the way it works with System.ArgumentException and its inheritors. The paramName parameter in constructors of System.ArgumentException and its derivatives (for example System.ArgumentNullException, System.ArgumentOutOfRangeException, and so on) expects the name of the parameter that caused the exception as it will appear in stack traces to help you quickly find the source of the problem. Therefore, ReSharper issues a warning if the literal in the argument corresponds to none of the parameters of the method where the exception is thrown. Moreover, ReSharper is aware of the position of the paramName parameter in different signatures as shown in the example below.

public void Foo(object value) { if(value == null) // Warning for unresolved symbol, where paramName is the first argument throw new ArgumentNullException("bad value", "value is null"); if(!(value is string)) // Warning for unresolved symbol, where paramName is the second argument throw new ArgumentException("bad value", "value is not string"); // do something }
Last modified: 21 July 2022