Search code examples
c#.netwindowswindows-store-appsobservablecollection

Why are all of the methods of an ObservableCollection missing in my project?


It seems like there are methods and properties of ObservableCollection that are missing. I'm so confused.

Here is a screenshot of an old project:enter image description here

And now my current project: enter image description here

This is the using statement in both projects:

using System.Collections.ObjectModel;

Did they update the SDK and removed all of the methods or am I using the wrong ObservableCollection? I have no idea what's going on.


Solution

  • When you see the down arrow on a method enter image description here that means that method is not part of the class but is a "Extension Method". Extension methods are basically static methods from other classes that act like instance methods on the class you are working with.

    Most of the items in your list are from adding using System.Linq; to the top of your file. This causes all of the extension methods in System.Linq.Enumerable to show up in the list, this will give you things like All<> or Any<>. However AddRange<> is not a standard extension method in System.Linq and may be added by some other 3rd party library (or some namespace in .NET I am not aware of) that you are using.

    The easiest way to find out where you are getting AddRange<> from is go to the project that it works for and then right click on the method in code and you should see a "Go To Definition" or similar1, that should take you to the file or the metadata view of the file that declared that extension method.

    1: I use Resharper and it changes my right click menu so I don't know the exact wording