title: Activator.CreateInstance: Could not load type from assembly
body: <p>I'm trying to create an instance of a class implemented in a plugin .dll in my project to do type discovery. I'm receiving this exception:</p>
  
  <blockquote>
    <p>Could not load type 'Action' from assembly
    'SquidReports.DataCollector.Plugin.BES, Version=1.0.0.0,
    Culture=neutral, PublicKeyToken=null'.</p>
  </blockquote>
  
  <p>This is the exact method signature I'm using:
  <a href="https://msdn.microsoft.com/en-us/library/d133hta4(v=vs.110).aspx" rel="noreferrer">https://msdn.microsoft.com/en-us/library/d133hta4(v=vs.110).aspx</a></p>
  
  <p>In other words, I'm attempting to spawn the object based on the Assembly name and the class name, like so:</p>
  
  <pre><code>object modelObject = Activator.CreateInstance((string)modelInfo.AssemblyName, (string)modelInfo.ModelName);
  </code></pre>
  
  <p>An important part to note here is that I'm using the 'Short' name of the assembly as opposed to the 'full' name (including Version, Culture and PublicToken).
  However, MSDN clearly states:</p>
  
  <blockquote>
    <p>'assemblyName' can be either of the following: The simple name of an
    assembly, without its path or file extension.</p>
    
    <ul>
    <li><p>For example, you would
    specify TypeExtensions for an assembly whose path and name are
    .\bin\TypeExtensions.dll.</p></li>
    <li><p>The full name of a signed assembly, which
    consists of its simple name, version, culture, and public key token;
    for example, "TypeExtensions, Version=1.0.0.0, Culture=neutral,
    PublicKeyToken=181869f2f7435b51".</p></li>
    </ul>
  </blockquote>
  
  <p>Specifically, I'm trying to create an instance of class 'Action' defined in the Assembly 'SquidReports.DataCollector.Plugin.BES'.
  I'm explicitly referencing this assembly as a <em>using</em> directive at the top of the exact same *.cs file where I'm trying to create the instance.</p>
  
  <p>I've tried the following suggestions from previous questions/answers:</p>
  
  <p>Clean out your solution, rebuild and try again
  This seems to work in some ASP.NET projects, but this is plain old console app.</p>
  
  <p>Check the referenced assemblies in your config file
  Again, this is a simple console app that only uses the GAC and libraries in the different projects of the same solution</p>
  
  <p><strong>1. Make sure the assembly is in the correct working directory:</strong></p>
  
  <p>Here we are...</p>
  
  <p><img src="https://i.stack.imgur.com/UdK5t.png" alt="It&#39;s right there!!!"></p>
  
  <p><strong>2. Make sure the assembly is the same version on-disk</strong></p>
  
  <p>Yup...</p>
  
  <p><img src="https://i.stack.imgur.com/ZmBQG.png" alt="Looks the same"></p>
  
  <p><strong>3. The final recommendation was to use fuslogvw.exe.</strong></p>
  
  <p>I Have no experience using the tool, but there is one thing that I did find odd. Upon running the debug session, both a long-named and short-named version of my assembly showed up:</p>
  
  <p><img src="https://i.stack.imgur.com/aL7lU.png" alt="Hmmm..."></p>
  
  <p>I had a look at both logs.</p>
  
  <p>The short-named version does seem to generate some warnings:</p>
  
  <blockquote>
    <p>=== Pre-bind state information ===</p>
    
    <p>LOG: DisplayName = SquidReports.DataCollector.Plugin.BES Partial)
       WRN: Partial binding information was supplied for an assembly:</p>
    
    <p>WRN: Assembly Name: SquidReports.DataCollector.Plugin.BES | Domain ID: 1</p>
    
    <p>WRN: A partial bind occurs when only part of the assembly display name is provided.</p>
    
    <p>WRN: This might result in the binder loading an incorrect assembly.</p>
    
    <p>WRN: It is recommended to provide a fully specified textual identity for the assembly,</p>
    
    <p>WRN: that consists of the simple name, version, culture, and public key token.</p>
    
    <p>WRN: See whitepaper <a href="http://go.microsoft.com/fwlink/?LinkId=109270" rel="noreferrer">http://go.microsoft.com/fwlink/?LinkId=109270</a> for more information and common solutions to this issue.</p>
  </blockquote>
  
  <p>... but it ends with being loaded successfully, and it clearly mentions my assembly at the correct location:</p>
  
  <blockquote>
    <p>LOG: Attempting download of new URL file:///C:/Source/C#/SquidReports/SquidReports.DataCollector/bin/x86/Debug/SquidReports.DataCollector.Plugin.BES.DLL.</p>
  </blockquote>
  
  <p>The log for the long-named version contains no suspicious messages.</p>
  
  <p>Any more ideas?</p>
  
  <p><strong>EDIT</strong>: Here is a minimal definition of the Action class. It's purely a model-class.</p>
  
  <pre><code>public class Action : ICollectible
  {
      public Action()
      {
          // Empty constructor
      }
  
      public Action(int actionID, string siteID, string name)
      {
          this.ActionID = actionID;
          this.SiteID = siteID;
          this.Name = name;
      }
  
      public int ID           { get; set; }   // Identity ID assigned by DB
      [Key]
      public int ActionID     { get; set; }   // Identity ID assigned by API
      public string SiteID    { get; set; }
      public string Name      { get; set; }
  }
  </code></pre>
  
  <p>ICollectible interface and [Key] attribute are part of yet another assembly. Not sure if that would have effect?</p>
  
  <p><strong>EDIT 2:</strong> As Erik points out below, obviously I have done the exact same checks on this OTHER assembly as well.</p>