title: Where does Visual Studio look for assemblies?
body: <p>I've got a framework which consists of many base classes that can be derived to develop many apps. Among these classes there is a subclass of System.Windows.Forms.Panel for which I wrote its own designer. Everything is working fine with Visual Studio 2005, but something goes wrong when I try to move to VS2010. This is a much simplified version of what I am doing:</p>
  
  <p>I have a project called CoreClasse which contains an interface and two classes:</p>
  
  <pre><code>public interface IConf
  {
      string foo { get; set; }
      void InitFoo();
  }
  
  public class SimpleClass
  {
      public string foo;
  }
  
  public class ConfLoader
  {
      public static IConf LoadConf()
      {
          AssemblyName anAssemblyName = new AssemblyName("ConfClasses");
          Assembly anAssembly = Assembly.Load(anAssemblyName);
          IConf result = (IConf)anAssembly.CreateInstance("ConfClasses.ConfClass");
          result.InitFoo();
          return result;
      }
  }
  </code></pre>
  
  <p>Then there is a project ConfClasses which references CoreClasses and contains just one class implementing IConf:</p>
  
  <pre><code>public class ConfClass : IConf
  {
      public SimpleClass confVal;
  
      public string foo
      {
          get { return confVal.foo; }
          set { confVal.foo = value; }
      }
  
      public void InitFoo()
      {
          confVal = new SimpleClass();
          confVal.foo = "bar";
      }
  }
  </code></pre>
  
  <p>And finally there is a project for the controls which references only CoreClasses and contains a subclass of Panel and the associated designer:</p>
  
  <pre><code>[Designer("MyControls.Design.SimplePanelDesigner", typeof(IRootDesigner))]
  public class SimplePanel : Panel
  {
      public SimpleClass dummy = new SimpleClass();
  }
  
  public class SimplePanelDesigner : DocumentDesigner
  {
      public IConf DesignerConf;
  
      public SimplePanelDesigner()
          : base()
      {
          DesignerConf = ConfLoader.LoadConf();
      }
  }
  </code></pre>
  
  <p>Now I create another solution which references all these dlls and contains an empty subclass of SimplePanel. When I double click on this class in SolutionExplorer the constructor of SimplePanelDesigner is executed and the method LoadConf of ConfLoader is called. This means that ConfClasses.dll is loaded dinamically and an instance of ConfClass is created. Everything is fine up to this moment, but when InitFoo is called this exception is raised:</p>
  
  <p><em>Could not load file or assembly 'CoreClasses, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.</em></p>
  
  <p>To make things harder, the exception is not actually raisedin this example, but this is exactly the kind of istructions my real app is executing, and the exception I am getting. I haven't got a clue of what's happening here. VS is executing a method which IS in CoreClasses. Why is it trying to load it again? And where is it looking for it? I checked the current AppDomain, too, but it has CoreClasses among its loaded assemblies, and it does not seem to change.</p>
  
  <p>Just to add some more details, every project is build in a common folder (not the usual obj/debug folder inside the project folder), and there is no other copy of my dlls on the PC at the moment I start my test. Then a copy of all the referenced dlls is done in a series of folders in the AppData\Local\Microsoft\VisualStudio\10.0\ProjectAssemblies folder of my userprofile, and this seems to be the place VS is looking for the assemblies when Assembly.Load is executed, and I can find a copy of CoreClasses there. I tried to clean all the folders, to rebuild everything, and to keep the different solutions opened/closed in every combination, but without any improvement. </p>
  
  <p>EDIT:</p>
  
  <p>As GranMasterFlush suggested, this is the FusionLog generated by the exception:</p>
  
  <pre><code>=== Pre-bind state information ===
  LOG: User = FCDB\fc0107
  LOG: DisplayName = XEngine.Core, Version=1.0.0.1, Culture=neutral, PublicKeyToken=null (Fully-specified)
  LOG: Appbase = file:///C:/Program Files (x86)/Microsoft Visual Studio 10.0/Common7/IDE/
  LOG: Initial PrivatePath = NULL
  Calling assembly : (Unknown).
  ===
  LOG: This bind starts in default load context.
  LOG: Using application configuration file: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.Config
  LOG: Using host configuration file: 
  LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
  LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
  LOG: The same bind was seen before, and was failed with hr = 0x80070002.
  ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).
  </code></pre>
  
  <p>EDIT 2</p>
  
  <p>Just to add some info, I took a look at the fusion logs generated by my simple example and found out that exactly the same log has been generated while trying to load CoreClasses, but someway VisualStudio finds a way to cope with it.</p>