Unknown type when serializing

Topics: Web Api
Aug 25, 2011 at 9:21 PM

In my solution I can post a command to my REST server but I can't make posting several commands in one call to work. The problem now is that the types are not known. Some code maybe make it more clear.

[XmlRoot(Namespace = Schema.Default)]
public class CompositeCommand : CommandBase
  public CompositeCommand()

  public List<CommandBase> Commands { get; set; }

  public CompositeCommand(IEnumerable<CommandBase> commands)
    Commands = new List<CommandBase>(commands);


[WebInvoke(Method = HttpMethods.Post, UriTemplate = "composite")]
public HttpResponseMessage Post(HttpRequestMessage<CompositeCommand> request)
    var command = request.Content.ReadAs();   <= This fails with exception below

"The specified type was not recognized: name='SomeCommand', namespace='http://schemas.domain.net', at <Commands xmlns='http://schemas.domain.net'>."

Anyone that have been doing something similar?


Aug 26, 2011 at 1:39 PM

You'll most likely need to specify [KnownType(typeof(DerivedCommand))] for all your commands.


I'm not sure this is considered a best practice though.  I've read mixed opinions on blogs.