/// <summary> /// Reads a message into a typed object from the underlying stream /// </summary> /// <param name="inputStream"> The input stream to read from </param> /// <returns> The <see cref="object"/>. </returns> public object ReadMessage(Stream inputStream) { if (inputStream == null) { throw new ArgumentNullException("inputStream"); } // FIXME: This looks pretty wrong. BinaryReader reader = new BinaryReader(inputStream); int typeNameSize = reader.ReadInt32(); int messageSize = reader.ReadInt32(); byte[] typeNameBytes = reader.ReadBytes(typeNameSize); byte[] messageBytes = reader.ReadBytes(messageSize); string typeNameString = System.Text.Encoding.UTF8.GetString(typeNameBytes); // This will throw if the type is not known to the process Type messageType = Type.GetType(typeNameString); IMessageSerializer serializer = this.factory.CreateSerializer(messageType); object result = serializer.Read(messageBytes); return(result); }