title: Entity Framework Exception has been thrown by the target of an invocation
body: <p>I'm trying to make a really simple entity Framework Code First project, but can't manage to solve a "Exception has been thrown by the target of an invocation." when I'm trying to retrieve data from my database.</p>
  
  <p>I have a unique class :</p>
  
  <pre><code>public class TestStylo
  {
      [Key]
      public int TestStyloID { get; set; }
      StyloType styloType { get; set; }
      public string name;
  
      public TestStylo(StyloType styloType, string name)
      {
          this.styloType = styloType;
          this.name = name;
      }
      public StyloType getTypeStylo{
          get { return styloType; }
      }
  
  
  }
  public enum StyloType
  {
      pen,
      wood,
      gold
  }
  </code></pre>
  
  <p>my Model is :</p>
  
  <pre><code>public class Model1 : DbContext
  {
       public Model1()
          : base("name=Model1")
      {
      }
  
      public  DbSet&lt;TestStylo&gt; MyStylos { get; set; }
  }
  </code></pre>
  
  <p>And my App.Config is :</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;configSections&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
    &lt;/configSections&gt;
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
    &lt;connectionStrings&gt;
      &lt;add name="Model1" connectionString="data source=(LocalDb)\v11.0;initial catalog=TestCodeFirst.Model1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>My connectionString is working, I can manually open and see my database and it's content.
  When I try to add content to my database I use :</p>
  
  <pre><code>using (Model1 db = new Model1())
              {
                  TestStylo stylo = new TestStylo(StyloType.pen,"numberOne");
                  db.MyStylos.Add(stylo);
                  db.SaveChanges();
              }
  </code></pre>
  
  <p>and it works for the most part (it only insert the ID .. but I'll see that later)</p>
  
  <p>But when I try to retrieve with :</p>
  
  <pre><code>private void button2_Click(object sender, EventArgs e)
          {
              using (Model1 db = new Model1())
              {
                  var stylos = from order in db.MyStylos
                                select order;
  
                  ...
              }
          }
  </code></pre>
  
  <p>I'm getting an <code>"Exception has been thrown by the target of an invocation."</code> with an Inner-Exception <code>{"The class 'TestCodeFirst.TestStylo' has no parameterless constructor."}</code>.</p>
  
  <p>Why am I getting such an error ?</p>