title: Precompile protobuf-net Type Model for compact framework
body: <p>I am deserializing thousands of objects on compact framework (3.5) and it is slow. Taking the devices 20+ seconds to finish. I found that it's done by reflection, instead of compile-and-run like non compact counterpart.
  So I thought, could I pre-compile and generate a type model dll first?</p>
  
  <p>So I did the following:</p>
  
  <ol>
  <li>Extract all the Contract class to a smart device dll (it references Protobuf-net CF3.5 Dll)</li>
  <li><p>Create a desktop 3.5 console application, referencing Protobuf-net "Desktop" Dll and the Contract Dll created above.</p>
  
  <pre><code>class Program
  {
    static void Main(string[] args)
    {
      var bb = TypeModel.Create();
  
      foreach (var t in Assembly.GetAssembly(typeof(My.ContractX)).GetTypes())
      {
          var contract = t.GetCustomAttributes(typeof (ProtoBuf.ProtoContractAttribute), false);
          if (contract.Length &gt; 0)
          {
              bb.Add(t, true);
          }
      }
      bb.Compile("My.TypeModel", "My.Serialization.dll");
    }
  }
  </code></pre></li>
  <li>Back to the device project, reference the Contract DLL, the generated My.Serialization.dll, and Protobuf-net CF3.5 Dll.</li>
  <li>Instead of using the default model, modified it to deserialize with the model constructed by "new TypeModel()"</li>
  </ol>
  
  <p>It actually compiles correctly. I look at the generated dll in the Reflector, it's as expected.</p>
  
  <p>Except that upon running, it throws MissingMethodException. However exactly what is missing is missing because compact framework doesn't report that.</p>
  
  <p>My bet is because the generated My.Serialization.dll actually refers to the "Desktop" dll, but some method is missing.</p>
  
  <p>So back to my question, how could I achieve type model pre-generation to be used in compact framework? Or could I get performance boost by doing something else?</p>