title: Unable to Load configProtectedData Provider
body: <p>I have a Referenced Assembly where CopyLocal = True, The file is present in the bin folder, but it is not being copied to Temporary ASP.NET Files when I run the solution from Visual Studio</p>
  
  <p>The error message is  the usual:</p>
  
  <pre><code>An error occurred loading a configuration file: Could not load file or assembly 'MyNamespace.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. 
  </code></pre>
  
  <p><strong>Solution / Actual Cause</strong></p>
  
  <blockquote>
    <p>There were a number of problems:</p>
    
    <p>Problem 1: In order to load a configProtectedData Provider, at least in my environment - the assembly must be in the GAC.</p>
    
    <p>The reason for this was revealed by the fusion logs. Although my web app could locate the assembly in the bin folder - the web server (IIS Express) <em>also needs to load it</em> and it was this part that was failing. Since the web server has no knowledge of my bin folder, the only place it can possibly get the file from is the GAC. Fusion shows that IIS Express was having-a-go at looking in Temp ASP .Net folders but I think that this might be some kind of fallback and in my case the shadow copy was indeed copying the assembly but to a different location (Temporary ASP.NET Files\root\4f27e88a\bfcf2f79\assembly\dl3\06324d99\85ff3c73_1943cf01) that IIS Express didn't know to look for.</p>
    
    <p>Problem 2: Once I had the assembly in the GAC properly, (surprise) Typo. I had the class name wrong in the "type" attribute</p>
  </blockquote>
  
  <p><strong>The thought process to get to the Solution</strong></p>
  
  <p>First: Follow Ivan Niktin's debugging process, Second <a href="http://www.hanselman.com/blog/BackToBasicsUsingFusionLogViewerToDebugObscureLoaderErrors.aspx" rel="nofollow">Fusion Logs are your friend</a></p>
  
  <p>It makes sense that it is trying to load it from Temporary ASP.Net Files as this is an MVC Web Application.</p>
  
  <p>What doesn't makes sense is that the Temporary ASP.Net Files location that is being searched is empty. If I add the assembly to the GAC then it loads fine, but this is not an option for my deployment scenario.</p>
  
  <p>The Fusion Log shows as the first path searched:</p>
  
  <pre><code>LOG: Attempting download of new URL file:
  ///C:/Users/Rob/AppData/Local/Temp/Temporary ASP.NET Files/root
  /4f27e88a/bfcf2f79/MyNamespace.Configuration.DLL
  </code></pre>
  
  <p>The other paths are:</p>
  
  <pre><code>.../MyNamespace.Configuration.DLL
  .../MyNamespace.Configuration/MyNamespace.Configuration.DLL
  .../MyNamespace.Configuration.EXE
  .../MyNamespace.Configuration/MyNamespace.Configuration.EXE
  </code></pre>
  
  <p>When I view the content of the folder that is being searched for the DLL - It is empty!</p>
  
  <p>There is only one namespace involved MyNamespace.Configuration - this is a new / nearly empty assembly with no dependencies other than <em>System</em>.Configuration in the GAC, the host project and referenced assembly are both using .Net Framework 4.0</p>
  
  <p>The part of the application that is trying to load the affected assembly is:</p>
  
  <pre><code>&lt;configProtectedData defaultProvider="DynamicFileConfigurationProvider"&gt;
          &lt;providers&gt;
              &lt;add name="DynamicFileConfigurationProvider"
                   type="MyNamespace.Configuration.DynamicFileConfigurationProvider, 
                      MyNamespace.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aeecd94c462a579a"
                   SelectorKeyProviderName="HostNameSelectorKeyProvider"/&gt;    
          &lt;/providers&gt;
      &lt;/configProtectedData&gt;
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>Setting shadowCopyBinAssemblies to false had the effect of causing the binder to look at ../Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/... Rather than the previous IIS Express location</p>
  
  <p>Intercepting the exception earlier did not provide any additional information, simply the same message that the file could not be found.</p>
  
  <p>Referencing the assembly in another host, both console and web turned up no info, the assembly loads fine and the methods can be called.</p>
  
  <p>Manually placing the assembly in the location in which the binder is looking for it also works - It seems to me that the assembly binder is looking in the wrong place. i.e. if shadowCopyBinAssemblies is false, then it should only look in the bin folder. if shadowCopyBinAssemblies is true then the shadow copy location should have my app's dll's as well as any that it references - it shouldn't be empty.</p>