News for hackers. Stuff that matters.
Re:.NET Framework 4.6.2 by moogly on Tuesday August 02, 2016 @08:48PM (#12214667)
Common, popular, coding styles with a lot of inlined code instead of temporaries will have this issue:

  public Result MapResult(IntermediateType src)
  {
      return new Result
      {
          Property1 = src.Property1,
          Property2 = src.Indirection.Property,
          [...]
      };
  }
or, in C# 6

  public Result MapResult(IntermediateType src)
      => new Result
      {
          Property1 = src.Property1,
          Property2 = src.Indirection.Property,
          [...]
      };

     
if Indirection is null here (or indeed anything that can throw an NRE within the initializer), the NRE will reference the line starting with return/=>
Re:.NET Framework 4.6.2 by kmc059000 on Tuesday August 02, 2016 @09:39PM (#12214936)
This is usually where I get NREs too and is the most frustrating. When using object initializers, the line number is the same for the entire initializer, so you don't get much help in determining exactly which line the exception was on.

I imagine there is a reason why it's hard, but it seems like it should be easy and incredibly valuable to know which property assignment caused the exception.

Regardless, I agree that this is a major source of NREs

Re:.NET Framework 4.6.2 by ygra on Wednesday August 03, 2016 @02:44AM (#12216086)
Good point, thank you. We're still rather conservative, so except for nameof I haven't yet used any C# 6 features, and the code we write often doesn't look like that, so I tend to forget a few problematic styles sometimes.