title: Map readonly fields with Automapper
body: <p>I have two identical classes in different namespaces:</p>
  
  <pre><code>namespace ClassLibrary1
  class Class1
  {
      public readonly int field1;
      public Class1(int value) { field1 = value; }
  }
  </code></pre>
  
  <p>And the same class definition in namespace <code>ClassLibrary2</code>.</p>
  
  <p>When I try to use AutoMapper, I get this exception: </p>
  
  <blockquote>
    <p>Expression must be writeable Parameter name: left</p>
  </blockquote>
  
  <p>This is the code of AutoMapper:</p>
  
  <pre><code>Mapper.CreateMap&lt;ClassLibrary1.Class1, ClassLibrary2.Class1&gt;();
  var result = Mapper.Map&lt;ClassLibrary2.Class1&gt;(class1);
  </code></pre>
  
  <p>But if I try this <a href="https://stackoverflow.com/questions/3146606/automapper-exclude-fields">AutoMapper Exclude Fields</a> it doesn't work, using this:</p>
  
  <pre><code>Mapper.CreateMap&lt;ClassLibrary1.Class1, ClassLibrary2.Class1&gt;()
      .ForMember(a =&gt; a.field1, a =&gt; a.Ignore());
  </code></pre>
  
  <p>For sure it works to change it to a property with public get and private set (like in <a href="https://stackoverflow.com/questions/19681768/automapper-ignore-readonly-properties">Automapper ignore readonly properties</a>), but I want to prevent a future developer of setting the value after constructor.</p>
  
  <p>Is there any way of solving this using AutoMapper?</p>