Local package repository with no permissions returns no results instead of throwing

Topics: General
Jul 12, 2012 at 10:34 PM

A customer had a local NuGet feed (say C:\Packages), and a site running under IIS was reading from it. The IIS application pool did not have permission to read the folder. When querying. the LocalPackageRepository returns an empty result set.

This led us to think something was going wrong with caching or something else - it wasn't obvious that it would be a permission problem. In the debugger, I can see that an UnauthorizedAccessException is thrown, but it is caught by:

NuGet.Core.dll!NuGet.PhysicalFileSystem.GetFiles(string path = {unknown}, string filter = {unknown}, bool recursive = {unknown})

In the code it looks like this:

    public virtual IEnumerable<string> GetFiles(string path, string filter, bool recursive)
      path = PhysicalFileSystem.EnsureTrailingSlash(this.GetFullPath(path));
      if (string.IsNullOrEmpty(filter))
        filter = "*.*";
        if (!Directory.Exists(path))
          return Enumerable.Empty<string>();
          return Enumerable.Select<string, string>(Directory.EnumerateFiles(path, filter, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly), new Func<string, string>(this.MakeRelativePath));
      catch (UnauthorizedAccessException ex)
      catch (DirectoryNotFoundException ex)
I expect that changing this behavior is out of the question, so I'm just sharing this in case anyone else encounters a similar problem. 


Jul 13, 2012 at 12:02 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.