NotSupportedException on PackageRepository.GetPackages() query expression

Topics: General
Aug 30, 2013 at 3:07 PM
I've been trying to use the Core API to integrate NuGet in my own application, using GetPackages() to retrieve an IQueryable, following the example on:

However, apparently there are many non-supported operations over the queryable. While the particular example listed on the blog works, if I do things like:

GetPackages().Where(p => p.IsListed()) or GetPackages().Where(p => p.IsReleaseVersion())
I get a NotSupportedException. If I try a similar one:

GetPackages().Where(p => p.Listed)
it throws an InvalidOperationException.

Is there any way to query the repository to include only listed/stable releases? It is true that it is possible to filter afterwards, but this screws up all the IQueryable composition, for example I can't use Skip() and Take() to implement proper paging server side, since my Where clause becomes meaningless and I don't know how many elements I should actually skip or take.
Aug 30, 2013 at 4:38 PM
Even more weird... while looking for alternative ways to do this, I realized that the Version property actually works, but again, not as you would expect...
The following throws an InvalidOperationException:

GetPackages().Where(p => p.Version.SpecialVersion == null);

However, the error message was particularly interesting: "No property 'SpecialVersion' exists in type 'Edm.String' at position 8."
This made me think "is it possible that the Queryable implementation actually considers version to be a String rather than a SemanticVersion object?".

Which led me to the following query:

GetPackages().Where(p => (((object)p.Version)) == (object)"5.0");

All the casts are to make sure that VisualStudio even allows me to compile the code... but surprisingly, it works!! This gave me the list of all the packages having exactly version string 5.0...

Unfortunately, I can't do much with this, since all other interesting methods like Contains seem to throw exceptions as well...

Did anyone notice this at all? I would expect this to be a big deal if you're looking for non-prerelease packages and so on. How does VisualStudio even deal with this in the first place?
Aug 30, 2013 at 5:34 PM
Ok, figured it out...

Turns out most of what you want is embedded in PackageRepository.Search() rather than PackageRepository.GetPackages(), including the option to filter prerelease versions.

I still think the API should be compatible with the service metadata, though.