Turning a byte array into a C# object whose type is unknown at compile time
I think, it can be simplified just a little bit:

static object Deserialize(byte[] buffer, Type type)
{
  using (StreamReader sr = new StreamReader(new MemoryStream(buffer)))
  {
    return JsonConvert.DeserializeObject(sr.ReadToEnd(), type);
  }
}


NB: StreamReader releases/disposes MemoryStream, so you don't have to encapsulate that in a using()



Or You could even do:

static object Deserialize(byte[] buffer, Type type)
{
  return JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(buffer), type);
}


or:

static object Deserialize(byte[] buffer, Type type)
{
  return JToken.Parse(Encoding.UTF8.GetString(buffer)).ToObject(type);
}