MQ throwing error when ExcludeTypeInfo is true

Working on a new dotnetcore app (1.0.43) , but having an issue with messaging.

IMessageService mq = new InMemoryTransientMessageService();
container.Register<IMessageService>(mq);
mq.RegisterHandler<TestMessage>(m => {
  return this.ExecuteMessage(m);
});
mq.Start();

ExecuteMessage fails with “Unable to resolve service ‘String’”

It seems because of this line, that is used in the project for other reasons.

ServiceStack.Text.JsConfig.ExcludeTypeInfo = true;

Comment this line out and the ExecuteMessage works fine. The problem is with it set to true, the Body in IMessage is a serialised string and so can’t be resolved.

Is this expected? Should it deserialise the Body of IMessage?

TypeInfo is only emitted when it’s needed (e.g. when using interfaces or object types) so using JsConfig.ExcludeTypeInfo = true should be a red flag as the TypeInfo you’re trying to suppress is usually needed by .NET Clients in order to serialize JSON into .NET Types.

It’s required by Message.Body which needs to be an object in order to be a generic message container that can hold any Request DTO.

OK, I’ll have to check back why the ExcludeTypeInfo was needed.

Can RegisterHandler not infer the type and do the conversion automatically? Would it not be better than just crashing?

Whilst I have you…

Would it be possible to include a version of RegisterHandler that has the “noOfThreads” parameter? Right now it has to be cast to the specific service type (AWS, Redis, Rabbit) but they all seem to support it. Except for InMemory, but isn’t that just a development version?

It’s likely you didn’t want the type info omitted to Ajax clients for Request DTOs that have interface or object properties, the solution here is to always use concrete Types.

How could it infer the Type? The Type Info is exactly what’s used to specify what Type the anonymous object should be deserialized into. We need to deserialize an annonymous Message into a Typed Message with a Typed Request DTO which is why the Type Info is needed.

The new APIs was added to IMessageService in this commit. This change is available from v4.5.13 that’s now available on MyGet.

Thanks for the noOfThreads, just makes my code cleaner and easier to switch.

Sorry if I’m being naive, I assumed since you provided the type as T in IMessageService.RegisterHandler<T> it could work it out.