LINQPad strange bug

The following code causes an Object reference not set to an instance of an object in LINQPad, but works in VS 2017:

var anObjectList = new List { "name", new[,] { { 1 } } };

Console.Write("Length ");
Console.WriteLine(anObjectList.Count());
Console.WriteLine(anObjectList[1]);

Comments

  • This code doesn't compile for me (in either linqpad or VS). I get "CS0305 Using the generic type 'List' requires 1 type arguments"
  • It looks like you're trying to create a list of anonymous type. I don't think that works. Try this instead.

    var anObjectList = new[] { o, o1 }.ToList();
  • Sorry, the post got mangled by the comment editor - trying again for the first line:

    var anObjectList = new List<object> { "name", new[,] { { 1 } } };

  • Works fine for me. What version of LINQPad are you using?
  • LINQPad 5.26.01 AnyCPU and x86. When I disabled My Extensions it works, so something must be happening there, but I have a LOT of extensions. I will have to try to narrow it down.
  • When I added all the imports and My Extensions to the query it still works, so now it is a little trickier...
  • I found it - I had a ToDump() on object in My Extensions that reformatted 2D arrays improperly. I didn't realize Console.WriteLine would call ToDump.

    Sorry - never mind!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!