Updated on

Serialization turns a C# object into a string or an array of bytes that we can store or send, and deserialization turns that data back into the object. Let’s do both with JSON, XML and Protobuf, using one ASP.NET Core Web API and a console client.

To download the source code for this article, you can visit our GitHub repository.

Let’s dive into it.

What Is Serialization in C#?

Serialization is the process of converting the state of an object into a form (string, byte array, or stream) that can be persisted or transported. In C#, that form is usually JSON, XML or a binary format such as Protocol Buffers.

Deserialization is the process of converting the serialized stream of data into the original object state. This ensures that the original state is not altered and is recreated when we need it.

What we get depends on the format and the serializer. The format decides what the data looks like on the wire or on disk: text that people can read, or compact bytes that only a program can read. The serializer is the .NET class that does the conversion, such as JsonSerializer in System.Text.Json, XmlSerializer in System.Xml.Serialization, or Serializer from the protobuf-net library.

Both ends have to agree on the format. A JSON serializer can’t read XML, so an HTTP client tells the server which format it wants with the Accept header.

Why Do We Need Serialization and Deserialization?

Serialization is useful for the storage and exchange of object states. Within the application memory, the state of an object resides in complicated data structures which is unsuitable for storage or exchange over the network.

So, serialization converts the object into a shareable format.

With serialization, we can transfer objects:

  • Between client and server via REST APIs or GRPC
  • Over the network for messaging systems like Kafka or RabbitMQ
  • Through firewalls as JSON or XML strings
  • To other data stores like SQL or NoSQL databases for persistence

Deserialization is typically useful in reconstructing the object to its original state at its destination for further processing.

Demo Web API

Let’s use a Web API application that performs simple create and read operations on a list of employees:

[HttpGet]
[ProducesResponseType(typeof(IEnumerable<Employee>), StatusCodes.Status200OK)]
public IActionResult GetAllEmployees()
{
    return Ok(_repo.GetAll());
}

[HttpPost]
[ProducesResponseType(typeof(Employee), StatusCodes.Status201Created)]
public IActionResult CreateEmployee(Employee employee)
{
   _repo.Create(employee);
   return Created($"/employees/{employee.Id}", employee);
}

In this example, the Web API exposes two endpoints that get a list of employees and create a new employee respectively.

This Web API supports content transfer in multiple formats (XML, JSON, or Protobuf). The server chooses the data transaction format at runtime depending on the Accept and Content-Type header values in the request:

builder.Services.AddControllers()
    .AddProtobufFormatters()
    .AddXmlSerializerFormatters();

The AddXmlSerializerFormatters() method adds both input and output formatters, so we can serialize objects to and from XML. ASP.NET Core Web API adds the JSON formatter by default. So, there is no need to add it explicitly.

These concepts are part of the broader topic called content negotiation.

We are using the NuGet package WebApiContrib.Core.Formatter.Protobuf to support the Protobuf formatter here:

dotnet add package WebApiContrib.Core.Formatter.Protobuf

The package hasn’t had a release since version 3.0.0 in August 2020, but it still works on .NET 11: our tests send and receive Protobuf through it without changes.

Accordingly, the data contract model  contains the protobuf related attributes:

[ProtoContract]
public class Employee
{
    [ProtoMember(1)]
    public Guid Id { get; set; }

    [ProtoMember(2)]
    public string Name { get; set; } = string.Empty;

    [ProtoMember(3)]
    public Address? Address { get; set; }
}

[ProtoContract]
public class Address
{
    [ProtoMember(1)]
    public string AddressLine1 { get; set; } = string.Empty;

    [ProtoMember(2)]
    public string? AddressLine2 { get; set; }

    [ProtoMember(3)]
    public string City { get; set; } = string.Empty;

    [ProtoMember(4)]
    public string Country { get; set; } = string.Empty;
}

The EmployeeRepository is responsible for interaction with a persistent store for the employees:

public class EmployeeRepository : IEmployeeRepository
{
    private readonly Dictionary<Guid, Employee> _employees = new();

    public EmployeeRepository()
    {
        InitializeEmployeeStore();
    }

    public List<Employee> GetAll()
    {
        return _employees.Values.ToList();
    }

    public void Create(Employee employee)
    {
        if (employee == null)
        {
            return;
        }
        _employees[employee.Id] = employee;
    }
...
}

For simplicity, let’s use an in-memory dictionary as a persistent store for the employees. However, the repositories in an enterprise application will not use an in-memory dictionary. In such cases, it will interact with a relational or non-relational data source.

Let’s send a request to the API endpoint /api/Employees that returns the list of employees. We set the Accept header value as application/json:

curl -X 'GET' \
  'https://localhost:7181/api/Employees' \
  -H 'accept: application/json'

Hence, we get the response in JSON format:

[
  {
    "id": "1461c6dd-e5ee-4465-86e1-732c98bc3110",
    "name": "TestEmployee1",
    "address": {
      "addressLine1": "Street #1",
      "addressLine2": "District #1",
      "city": "Sample City2",
      "country": "Sample Country3"
    }
  },
  {
    "id": "0adbb1ef-756b-4f7f-aae7-3c165e572485",
    "name": "TestEmployee2",
    "address": {
      "addressLine1": "Street #2",
      "addressLine2": "District #2",
      "city": "Sample City3",
      "country": "Sample Country4"
    }
  },
 ...
]

Similarly, we set the Accept header as application/xml in the request header:

curl -X 'GET' \
  'https://localhost:7181/api/Employees' \
  -H 'accept: application/xml'

Consequently, we get the response in XML format:

<ArrayOfEmployee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Employee>
    <Id>1461c6dd-e5ee-4465-86e1-732c98bc3110</Id>
    <Name>TestEmployee1</Name>
    <Address>
      <AddressLine1>Street #1</AddressLine1>
      <AddressLine2>District #1</AddressLine2>
      <City>Sample City2</City>
      <Country>Sample Country3</Country>
    </Address>
  </Employee>
  <Employee>
    <Id>0adbb1ef-756b-4f7f-aae7-3c165e572485</Id>
    <Name>TestEmployee2</Name>
    <Address>
      <AddressLine1>Street #2</AddressLine1>
      <AddressLine2>District #2</AddressLine2>
      <City>Sample City3</City>
      <Country>Sample Country4</Country>
    </Address>
  </Employee>
  ...
</ArrayOfEmployee>

Finally, let’s see how the response looks when we set the Accept header as application/x-protobuf:

curl -s 'https://localhost:7181/api/Employees' \
  -H 'accept: application/x-protobuf' | xxd | head -6

The response in protobuf format isn’t human-readable, so let’s look at its first bytes in hex. We can spot values such as TestEmployee1 and Street #1, but none of the property names:

00000000: 0a5c 0a12 09dd c661 14ee e565 4411 86e1  .\.....a...eD...
00000010: 732c 98bc 3110 120d 5465 7374 456d 706c  s,..1...TestEmpl
00000020: 6f79 6565 311a 370a 0953 7472 6565 7420  oyee1.7..Street 
00000030: 2331 120b 4469 7374 7269 6374 2023 311a  #1..District #1.
00000040: 0c53 616d 706c 6520 4369 7479 3222 0f53  .Sample City2".S
00000050: 616d 706c 6520 436f 756e 7472 7933 0a5c  ample Country3.\

The ids come from Guid.NewGuid() and the city and country numbers from Random.Shared, so the JSON, XML and hex output on your machine won’t match ours byte for byte. The sizes stay the same.

Consuming the API

Let’s use a .NET console application as a consumer of the Web API described in the previous section.

The client application selects JSON, XML, or Protobuf for the exchange of data with the web API based on user input:

IClient client = format switch
{
    "json" => new JsonClient(),
    "cache" => new CachedJsonClient(),
    "xml" => new XmlClient(),
    "proto" => new ProtobufClient(),
    _ => new JsonClient()
};

Depending on the functional requirements, we may need to serialize a POCO (Plain Old CLR Object)  into a string or an array of bytes. For example, we may need to serialize a complex object into a JSON string and store it into a NoSQL DB like MongoDB or Redis.

There can also be a scenario where we use RabbitMQ for asynchronous communication between two service components. RabbitMQ doesn’t allow plain strings or complex types in the message body. In this case, we need the transfer object to be converted to byte[].

For such use cases, the client code supports string as well as byte array serialization and deserialization. This is indicated by the interfaces IStringSerializer and IByteSerializer.

The IStringSerializer implementation serializes a POCO to a string. Also, it can de-serialize a string to a POCO:

internal interface IStringSerializer
{
    T? Deserialize<T>(string text);

    string Serialize(object data);
}

Similarly, the IByteSerializer serializes a POCO to an array of bytes and vice-versa:

internal interface IByteSerializer
{
    T? Deserialize<T>(byte[] buffer);

    byte[] Serialize(object data);
}

We will explore the concrete implementations later on.

Irrespective of the format chosen by the client, we always see two lists of employees in the output. One before and the other after adding a new employee which includes the newly added employee:

Enter a format name(json, cache, xml, proto): cache

Employee list before adding an employee.
--------------------------------------
Name:TestEmployee1
Address:Street #1, District #1, Sample City4, Sample Country2

Name:TestEmployee2
Address:Street #2, District #2, Sample City1, Sample Country1

Name:TestEmployee3
Address:Street #3, District #3, Sample City2, Sample Country4

Name:TestEmployee4
Address:Street #4, District #4, Sample City3, Sample Country2

Name:TestEmployee5
Address:Street #5, District #5, Sample City4, Sample Country1

New employee TestEmployee6 has been added

Employee list after adding an employee.
--------------------------------------
Name:TestEmployee1
Address:Street #1, District #1, Sample City4, Sample Country2

Name:TestEmployee2
Address:Street #2, District #2, Sample City1, Sample Country1

Name:TestEmployee3
Address:Street #3, District #3, Sample City2, Sample Country4

Name:TestEmployee4
Address:Street #4, District #4, Sample City3, Sample Country2

Name:TestEmployee5
Address:Street #5, District #5, Sample City4, Sample Country1

Name:TestEmployee6
Address:Street #6, District #6, Sample City30, Sample Country22

The repository picks the city and country numbers with Random.Shared, so they change every time the API starts.

JSON Serialization

JSON serialization converts the public properties of an object into a string, byte array, or stream that conforms to the RFC 8259 JSON specification

In this demo, the JsonStringSerializer class implements the IStringSerializer interface. This wrapper class uses the JsonSerializer available in System.Text.Json to serialize and deserialize an object:

internal class JsonStringSerializer : IStringSerializer
{
     public T? Deserialize<T>(string text)
         => JsonSerializer.Deserialize<T>(text, _options);

     public string Serialize(object data)
         => JsonSerializer.Serialize(data, _options);
}

JsonStringSerializer also supports the passing of different serialization options through a parameterized constructor:

private readonly JsonSerializerOptions _options;

public JsonStringSerializer()
    : this(GetDefaultJsonSerializerOptions())
{
}

public JsonStringSerializer(JsonSerializerOptions options)
     => _options = options;

private static JsonSerializerOptions GetDefaultJsonSerializerOptions()
     => new JsonSerializerOptions(JsonSerializerDefaults.Web);

Let’s now see how this JsonStringSerializer is used in the JsonClient.

The GetAllEmployees() method uses the Deserialize() method in JsonStringSerializer class to convert the Web API response to a List:

public async Task<List<Employee>> GetAllEmployees()
{
      var url = $"{BaseUrl}/api/employees";
      var request = new HttpRequestMessage(HttpMethod.Get, url);
      request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
      
      var response = await _client.SendAsync(request);
      var content = await response.Content.ReadAsStringAsync();
      
      return _serializer.Deserialize<List<Employee>>(content) ?? [];
}

We set the Accept header as application/json here to instruct the server to return the response data in a format that conforms to JSON specifications. We use the ReadAsStringAsync() method to convert the HttpContent instance to a JSON string. Now, the code deserializes the resulting JSON to the intended C# object.

As the name suggests, the CreateEmployee() method sends an employee object to the Web API to create a new employee at the server:

public async Task<Employee?> CreateEmployee(Employee employee)
{
      var url = $"{BaseUrl}/api/employees";
      var request = new HttpRequestMessage(HttpMethod.Post, url);
      request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));            
      request.Content = new StringContent(_serializer.Serialize(employee), Encoding.UTF8, "application/json");
      
      var response = await _client.SendAsync(request);

      if (response.IsSuccessStatusCode)
      {
          var newEmployee = _serializer.Deserialize<Employee>(await response.Content.ReadAsStringAsync());
          return newEmployee;
      }

      return null;
}

Firstly, the Content-Type header is set as application/json to indicate the format used by the object in the request payload for content negotiation between the client and the server. Then, the Serialize() method serializes the new Employee POCO to a JSON string which is then used as StringContent in the HttpRequestMessage object.

For the serialization step on its own, outside an HTTP client, see our guide to serializing a C# object to a JSON string.

Using JSON Serialization in Caching

The caching mechanism in our client also uses JSON Serialization.

The IDistributedCache interface from the Microsoft.Extensions.Caching.Distributed namespace reads and writes data in an underlying cache store. Its GetAsync() and SetAsync() methods read and write a byte[], so an object has to be serialized before we can cache it. This is where we will be using the JsonByteSerializer.

The JsonByteSerializer class implements the IByteSerializer. This class also uses the same JsonSerializer but with minor tweaks to serialize and deserialize POCOs to byte[] instead of string and vice versa:

internal class JsonByteSerializer : IByteSerializer
{
     private readonly JsonSerializerOptions _options;

     public JsonByteSerializer()
         : this(GetDefaultJsonSerializerOptions())
     {
     }

     public JsonByteSerializer(JsonSerializerOptions options)
         => _options = options;

     public T? Deserialize<T>(byte[] buffer)
         => JsonSerializer.Deserialize<T>(buffer, _options);

     public byte[] Serialize(object data)
         => JsonSerializer.SerializeToUtf8Bytes(data, _options);

     private static JsonSerializerOptions GetDefaultJsonSerializerOptions()
         => new JsonSerializerOptions(JsonSerializerDefaults.Web);
}

The CachedJsonClient uses the JsonByteSerializer to get a list of employees and also create a new employee. But, it also uses a caching mechanism to improve performance:

public async Task<List<Employee>> GetAllEmployees()
{
       // Find cached item
       byte[]? objectFromCache = await _distributedCache.GetAsync(AllEmployeesKey);

       if (objectFromCache != null)
       {                
           var employees = _serializer.Deserialize<List<Employee>>(objectFromCache);
           return employees ?? [];
       }

       return await RefreshCache();
}

The GetAllEmployees() method reads the list of employees from the cache. If it can read the data from the cache, it deserializes the byte[] retrieved from cache to a List using the Deserialize() method from JsonByteSerializer.

private async Task<List<Employee>> RefreshCache()
{
       // If not found, then recalculate response
       var content = await GetResponseFromApi();
       var employees = _serializer.Deserialize<List<Employee>>(await content.ReadAsByteArrayAsync()) ?? [];

       var cacheEntryOptions = new DistributedCacheEntryOptions()
           .SetSlidingExpiration(TimeSpan.FromSeconds(10))
           .SetAbsoluteExpiration(TimeSpan.FromSeconds(30));

       // Cache it
       var resultAsByteArray = _serializer.Serialize(employees);
       await _distributedCache.SetAsync(AllEmployeesKey, resultAsByteArray, cacheEntryOptions);

       return employees;
}

private async Task<HttpContent> GetResponseFromApi()
{
       var url = $"{BaseUrl}/api/employees";
       var request = new HttpRequestMessage(HttpMethod.Get, url);
       request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
       
       var response = await _client.SendAsync(request);
       
       return response.Content;           
}

If there is a cache miss, the GetAllEmployees() method gets the data from the Web API and saves it in the cache. First, Deserialize() turns the response bytes into a list of employees. Then Serialize() turns that list back into a byte[], which is what we store.

Why not serialize the response string we already have? Because it’s already JSON. Serializing it again produces a JSON string that contains JSON, and reading that back as a List<Employee> throws a JsonException. The first version of this sample made exactly that mistake.

To move the cache out of our process, see our article on distributed caching in ASP.NET Core.

To learn more details about JSON Serialization using the System.Text.Json library, you can check our article on Introduction to System.Text.Json Through Examples.

XML Serialization

Similar to JSON serialization, XML serialization and deserialization is the process of conversion of C# objects to XML and vice versa. The custom XmlSerializer class used in this demo implements the IStringSerializer interface. It is a wrapper over the System.Xml.Serialization.XmlSerializer provided by .NET out of the box:

internal class XmlSerializer : IStringSerializer
{
    public T? Deserialize<T>(string text)
    {
        var serializer = new System.Xml.Serialization.XmlSerializer(typeof(T));

        using var reader = new StringReader(text);

        return (T?)serializer.Deserialize(reader);
    }

    public string Serialize(object data)
    {
        var serializer = new System.Xml.Serialization.XmlSerializer(data.GetType());

        using var writer = new Utf8StringWriter();
        serializer.Serialize(writer, data);

        return writer.ToString();
    }
}

internal class Utf8StringWriter : StringWriter
{
    public override Encoding Encoding => Encoding.UTF8;
}

The Serialize() method uses the StringWriter class from the System.IO namespace in conjunction with the out-of-the-box XML serializer to create an XML representation of the object as a string. Similarly, the Deserialize() method uses the StringReader to create an object by reading the string representation of an XML.

The XmlClient is very similar to the JsonClient. However, here, the Accept and Content-Type headers are set as application/xml instead of application/json.

request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

request.Content = new StringContent(_serializer.Serialize(employee), Encoding.UTF8, "application/xml");
To learn more about XML, check our articles on serializing objects to XML in C# and deserializing XML into C# objects.

Protobuf Serialization

Google developed Protocol Buffers or ProtoBuf for communication between their service components. It is a method of encoding and sending out structured data in an efficient manner. Protobuf is language-neutral, platform-neutral, and highly performant.

In this demo, the ProtobufSerializer class implements the IByteSerializer and acts as a wrapper over the Serializer class provided by the protobuf-net assembly. The protobuf-net is a contract-based serializer for the .NET code. Our shared models project references the protobuf-net package directly, and the WebApiContrib.Core.Formatter.Protobuf package from the Demo Web API section uses the same library on the server.

The protobuf-net Serializer doesn’t return a byte[], and the overloads we use here read from and write to a .NET Stream. Hence, the ProtobufSerializer methods use a MemoryStream in conjunction with the protobuf-net Serializer to convert POCOs to byte[] and vice-versa:

internal class ProtobufSerializer : IByteSerializer
{
     public T? Deserialize<T>(byte[] buffer)
     {
         using var stream = new MemoryStream(buffer);

         return Serializer.Deserialize<T>(stream);
     }

     public byte[] Serialize(object data)
     {
         using var stream = new MemoryStream();
         Serializer.Serialize(stream, data);

         return stream.ToArray();
     }
}

Since the data encoded in protobuf format is not human readable, the IByteSerializer is a better fit in this case compared to the IStringSerializer. We could have used MemoryStream directly as well in place of byte[], but we are maintaining consistency here by implementing the IByteSerializer.

In the next section, we will learn why Protobuf has become popular in recent times over the standard formatting like JSON or XML.

Let’s see how the ProtobufSerializer is used in the ProtobufClient:

public async Task<List<Employee>> GetAllEmployees()
{
      var url = $"{BaseUrl}/api/employees";
      var request = new HttpRequestMessage(HttpMethod.Get, url);
      request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-protobuf"));
      
      var response = await _client.SendAsync(request);
      var content = await response.Content.ReadAsByteArrayAsync();
      
      return _serializer.Deserialize<List<Employee>>(content) ?? [];
}

Similar to the JsonClient, the GetAllEmployees() method in ProtobufClient uses the Deserialize() method in the ProtobufSerializer class to convert the Web API response to a List. One difference is that the Accept header is set as application/x-protobuf as part of content negotiation with the Web API. Also, the HttpContent instance is read as byte[] from the response.

The ProtobufClient also has a CreateEmployee() method to create a new employee:

public async Task<Employee?> CreateEmployee(Employee employee)
{
      var url = $"{BaseUrl}/api/employees";
      var request = new HttpRequestMessage(HttpMethod.Post, url);
      request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-protobuf"));            
      request.Content = new ByteArrayContent(_serializer.Serialize(employee));
      request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf");
      
      var response = await _client.SendAsync(request);

      if (response.IsSuccessStatusCode)
      {
           var newEmployee = _serializer.Deserialize<Employee>(await response.Content.ReadAsByteArrayAsync());
           return newEmployee;
      }

       return null;
}

Here, the Content-Type header is set as application/x-protobuf to indicate the format used by the object in the request payload for communication between the client and the server. The Serialize() method from the ProtobufSerializer serializes the new employee POCO to a byte[] which is then used as ByteArrayContent in the HttpRequestMessage object.

Why Is Protobuf Serialization Gaining Popularity?

To date, JSON remains a very common format to communicate over HTTP. JSON has many obvious advantages as a data-interchange format. It is human readable, well understood, and typically performs well. But, in recent times protocol buffers have become increasingly popular.

Text-based serializers like JSON and XML have certain disadvantages:

  • They require complex parsing code to conform to human-readable options
  • They need more bandwidth as the property names also need to be part of the payload

Protocol buffers use a binary format. Furthermore, the message does not include the metadata defining the message content. For example, if our message has a property named EmployeeName then this name is not part of the message. In XML and JSON we will include EmployeeName as a string for each occurrence of the property in the message. Hence, protocol buffer messages are more compact in comparison to the same messages in XML or JSON.

In our demo, the same list of five employees comes back as 936 bytes of JSON, 1,374 bytes of XML and 470 bytes of Protobuf, so Protobuf is half the size of JSON here.

Protobuf is considered ideal for internal API communications between two server components within a distributed architecture where it helps in optimizing performance over low bandwidth networks.

gRPC uses Protobuf for its messages, and our introduction to gRPC in ASP.NET Core builds a service with it.

There are situations when JSON/XML is a better fit than something like Protocol Buffers, including situations where:

  • The data needs to be human-readable
  • A web browser consumes response data from a service
  • Our server application uses JavaScript

Each serialization format has its advantages and disadvantages. It depends on the context it is used.

For example, in an on-premises data center with low bandwidth, services can communicate using protobuf. Whereas, JSON is the simpler choice when we build our web client application using JS frameworks like Angular/React. We may also need XML serialization to make a system backward compatible with a client that is in a legacy platform.

Which Serializer Should We Use in .NET?

For most new code, System.Text.Json is the default. It ships with .NET, ASP.NET Core uses it for JSON out of the box, and JSON is what browsers and many other services expect.

XML still makes sense when a partner system or an older client only speaks XML. XmlSerializer covers that, and ASP.NET Core supports it as soon as we call AddXmlSerializerFormatters(), like our demo does.

Protocol Buffers fit traffic between our own services, where nobody reads the payload and size matters. protobuf-net gives us that with attributes on the classes we already have.

The one serializer we shouldn’t pick is BinaryFormatter, even though older tutorials still teach it. It isn’t safe even with data we think we can trust, and on .NET 11 the build stops with error SYSLIB0011. If we suppress that error, the call throws PlatformNotSupportedException at run time.

Microsoft’s BinaryFormatter security guide puts it plainly: “BinaryFormatter is insecure and can’t be made secure.” For old code that still uses it, the guide lists in-box replacements, including System.Text.Json and XmlSerializer, the two we’ve used in this article.

FormatSerializerWhere it comes fromReadable by peopleGood fit
JSONJsonSerializerSystem.Text.Json, part of .NETYesWeb APIs, browsers, caches
XMLXmlSerializerSystem.Xml.Serialization, part of .NETYesPartner or older systems that expect XML
Protocol BuffersSerializerprotobuf-net NuGet packageNoTraffic between our own services
BinaryBinaryFormatterRemoved from .NET 9 onwardNoNothing: it throws at run time

Serializing a class hierarchy needs extra setup, which our article on polymorphic serialization and deserialization covers.

Conclusion

In this article, we have covered the different use cases where serialization and deserialization in C# play a pivotal role.

It is important to understand that we cannot consider serialization as a one-size-fits-all approach. It depends on the usage and the different components that are involved in the systems that communicate among each other.

Tested with .NET 11 (SDK 11.0.100, runtime 11.0.0), protobuf-net 3.4.40 and WebApiContrib.Core.Formatter.Protobuf 3.0.0.