title: Protobuf-net Error: Type is not expected, and no contract can be inferred: BlockHeader
body: <p>Trying to get de-serialization of an openstreetmap pbf file working properly by following information from this thread as well as other sources:</p>
  
  <p><a href="https://stackoverflow.com/questions/4663298/protobuf-net-deserialize-open-street-maps">Protobuf-net Deserialize Open Street Maps</a></p>
  
  <p>I'm currently using the protobug dll from r480. I used protogen to create the csharp class files from the osm proto's, but when I hit this point in the code where I'm trying to read in from the stream:</p>
  
  <pre><code>BlockHeader header;
  using (var tmp = new LimitedStream(file, length))
  {
      header = Serializer.Deserialize&lt;BlockHeader&gt;(tmp); // exception occurs here
  }
  </code></pre>
  
  <p>It throws the following exception:</p>
  
  <pre><code>InnerException: System.InvalidOperationException
  Message=Type is not expected, and no contract can be inferred: BlockHeader
  Source=protobuf-net
  StackTrace:
    at ProtoBuf.Meta.TypeModel.ThrowUnexpectedType(Type type) in C:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs:line 1115
    at ProtoBuf.Meta.TypeModel.TryDeserializeAuxiliaryType(ProtoReader reader, DataFormat format, Int32 tag, Type type, Object&amp; value, Boolean skipOtherFields, Boolean asListItem, Boolean autoCreate, Boolean insideList) in C:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs:line 848
    at ProtoBuf.Meta.TypeModel.DeserializeCore(ProtoReader reader, Type type, Object value, Boolean noAutoCreate) in C:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs:line 582
    at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type, SerializationContext context) in C:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs:line 506
    at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type) in C:\Dev\protobuf-net\protobuf-net\Meta\TypeModel.cs:line 488
    at ProtoBuf.Serializer.Deserialize[T](Stream source) in C:\Dev\protobuf-net\protobuf-net\Serializer.cs:line 69
    at OsmParserDemo.MainWindow.OsmParse() in C:\Users\crussell\Documents\Visual Studio 2010\Projects\OsmParseMadness\OsmParserDemo\MainWindow.xaml.cs:line 57
    at OsmParserDemo.MainWindow..ctor() in C:\Users\crussell\Documents\Visual Studio 2010\Projects\OsmParseMadness\OsmParserDemo\MainWindow.xaml.cs:line 28
  </code></pre>
  
  <p>So in comparing the code structure to that of the protobuf-net example I get the impression that I may be missing something in regards to identifying each member. Is this correct, or am I way out in space on this one? Any help or hints are greatly appreciated!</p>
  
  <p>Edit: Here's a snippet of BlockHeader from the generated FileFormat.cs class:</p>
  
  <p><a href="http://pastebin.com/SDPAFp77" rel="noreferrer">BlockHeader</a></p>