title: Activator.CreateInstance(Type) for a type without parameterless constructor
body: <p>Reading existing code at work, I wondered how come this could work. I have a class defined in an assembly :</p>
  
  <pre><code>[Serializable]
  public class A
  {
      private readonly string _name;
      private A(string name)
      {
          _name = name;
      }
  }
  </code></pre>
  
  <p>And in another assembly :</p>
  
  <pre><code>public void f(Type t) {
      object o = Activator.CreateInstance(t);
  }
  </code></pre>
  
  <p>and that simple call <code>f(typeof(A))</code></p>
  
  <p>I expected an exception about the lack of a parameterless constructor because AFAIK, if a ctor is declared, the compiler isn't supposed to generate the default public parameterless constructor.</p>
  
  <p>This code runs under .NET 2.0.</p>
  
  <p>[EDIT] I'm sorry but I misread the actual code... The sample I provided doesn't illustrate it. I accepted JonH answer because it provided a good piece of information.</p>