title: Access denied leading to mscorlib.dll
body: <p>Been a lurker for a long time, first post. So just let me know what I need to do if I'm unclear, not enough information, etc.</p>
  
  <p>System: Windows 7 VS2012 C#</p>
  
  <p>Trying to just run the code from here, first method:
  <a href="http://msdn.microsoft.com/en-us/library/bb546133.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb546133.aspx</a></p>
  
  <p>And it works as is for any file within my user directory, but not the user directory itself.
  C:\Users\me\dir not C:\Users\me or up.
  Getting System.UnauthorizedAccessException on C:\documents and settings</p>
  
  <p>Looking around, most posts I found said to just </p>
  
  <pre><code>static void QueryDuplicates()
      {
        try
        { //Query for Duplicates }
        catch {//left blank}
      }
  </code></pre>
  
  <p>Which I think is insecure so I tired:</p>
  
  <pre><code>catch (Exceptions ex)
  {
  if {ex is System.UnauthorizedAccessException} {} 
  else {Console.writeline(ex.message);}
  }
  </code></pre>
  
  <p>which I guess is a little better :-(</p>
  
  <p>That bypasses the original error but now I get 
  "A first chance exception of type 'System.UnauthorizedAccessException'occured in mscorlib.dll"
  I find this odd because shouldn't this have been skipped over?</p>
  
  <p>The best I've found is to make a manifest, but I'd rather not be skipping errors and then forcing a program to run as admin. Seems really insecure and a bandaid solution.</p>
  
  <p><a href="http://blogs.msdn.com/b/nikhiln/archive/2007/04/19/embed-a-manifest-to-make-an-application-elevate-in-vista.aspx" rel="nofollow">http://blogs.msdn.com/b/nikhiln/archive/2007/04/19/embed-a-manifest-to-make-an-application-elevate-in-vista.aspx</a></p>
  
  <p>The end result I'm looking for is to loop through a whole drive and find all the duplicate files. At least this is the first step in the program I'm writing. I'm looking for either a better solution than what I'm trying, a true fix for the issues, or anything to try.</p>