runtime: Inconsistent `ParamName` for `ArgumentException`s

This small piece of code:

using System;
using System.Net;

public class Program
{
  public static void Main()
  {
    var client = new WebClient();
    try
    {
      client.Encoding = null;
    }
    catch (ArgumentException e)
    {
      Console.WriteLine(e.ParamName);
    }

    try
    {
      client.BaseAddress = "invalid address";
    }
    catch (ArgumentException e)
    {
      Console.WriteLine(e.ParamName);
    }
    
  }
}

prints the following output:

Encoding
value

The expected output is either:

value
value

or

Encoding
BaseAddress

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 18 (15 by maintainers)

Most upvoted comments

@buyaa-n Given that the analyzer is enabled in the repo, I think yes we can close. Any enhancements of the analyzer will get reflected here when it’s updated.

@louis-z the data flow analysis could help with this scenario is interprocedural analysis

If you want to work on it here are some suggestions:

  • I believe we don’t need a new analyzer for this, it should be an improvement to the existing analyzer
  • As analyzers are in different repo, please file an issue into roslyn-analyzers.
  • Instruction for getting started with NetCore analyzers
  • The existing analyzer code is here
  • Data flow analysis is expensive, I believe we wouldn’t like it enabled by default, you might need to make the existing analyzer configurable with interprocedural analysis

With that being said as the issue mentioned here is fixed and the remaining question is related to roslyn-analyzer we could close this issue, what you think @Youssef1313