2
votes

I'm just getting refamiliarized with NServiceBus and I'm receiving a MessageDeserialization exception and stack trace as shown below.

For some environmental information... I'm using azure persistence with Queues. I can see the subscription table and what looks like all the endpoint addresses for my subscribers.

I have 3 MVC Web API hosted apps. The Service/API publishing the message that causes this exception is configured in its app.config to subscribe to itself and 2 other apis. The others that don't seem to have a problem have only 1 subscription. The first subscribes to one of its own events. And the other subscribes to 3 events from the 3rd service/api.

Things I've tried in order to resolve the issue. I was using conventions to define my events, but now my event messages all implement IEvent. I've also defined the JsonSerializer. Here's my bus configuration setup...

public class NServiceBusEndpointConfig : IConfigureThisEndpoint, AsA_Worker
{
    public static IBus bus;

    public void Customize(BusConfiguration busConfig)
    {
        var configuration = ContainerConfig.Container.Resolve<ICredentialDomainConfig>();

        busConfig.AzureConfigurationSource();
        busConfig.UseTransport<AzureStorageQueueTransport>()
            .ConnectionString(configuration.NServiceBusQueueConnectionString);
        busConfig.UsePersistence<AzureStoragePersistence>();
        busConfig.EndpointName("service1");

        busConfig.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(ContainerConfig.Container));
        busConfig.UseSerialization<JsonSerializer>();  
        busConfig.License(configuration.NServiceBusLicenseString);
    }
}

}

Here is the exception and stack trace details...

"NServiceBus.ExceptionInfo.ExceptionType": "NServiceBus.MessageDeserializationException",
      "NServiceBus.ExceptionInfo.InnerExceptionType": "System.Exception",
      "NServiceBus.ExceptionInfo.HelpLink": null,
      "NServiceBus.ExceptionInfo.Message": "An error occurred while attempting to extract logical messages from transport message

8dea1c2f-babb-438d-8e4c-a4cd002f5ab6", "NServiceBus.ExceptionInfo.Source": "NServiceBus.Core", "NServiceBus.ExceptionInfo.StackTrace": "NServiceBus.MessageDeserializationException: An error occurred while attempting to extract logical messages from transport message 8dea1c2f-babb-438d-8e4c-a4cd002f5ab6 ---> System.Exception: Could not find metadata for 'Newtonsoft.Json.Linq.JObject'.\r\nPlease ensure the following:\r\n1. 'Newtonsoft.Json.Linq.JObject' is included in initial scanning. \r\n2. 'Newtonsoft.Json.Linq.JObject' implements either 'IMessage', 'IEvent' or 'ICommand' or alternatively, if you don't want to implement an interface, you can use 'Unobtrusive Mode'.\r\n at NServiceBus.Unicast.Messages.LogicalMessageFactory.Create(Type messageType, Object message, Dictionary2 headers) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Unicast\\Messages\\LogicalMessageFactory.cs:line 59\r\n at System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()\r\n at System.Collections.Generic.List1..ctor(IEnumerable1 collection)\r\n at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)\r\n
at NServiceBus.DeserializeLogicalMessagesBehavior.Extract(TransportMessage physicalMessage) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Unicast\\Messages\\DeserializeLogicalMessagesBehavior.cs:line 93\r\n at NServiceBus.DeserializeLogicalMessagesBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Unicast\\Messages\\DeserializeLogicalMessagesBehavior.cs:line 40\r\n --- End of inner exception stack trace ---\r\n at NServiceBus.DeserializeLogicalMessagesBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Unicast\\Messages\\DeserializeLogicalMessagesBehavior.cs:line 47\r\n at NServiceBus.BehaviorChain
1.InvokeNext(T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107\r\n at NServiceBus.BehaviorChain1.<>c__DisplayClass5.<InvokeNext>b__2() in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Pipeline\\BehaviorChain.cs:line 95\r\n at NServiceBus.ApplyIncomingTransportMessageMutatorsBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\MessageMutator\\ApplyIncomingTransportMessageMutatorsBehavior.cs:line 20\r\n at NServiceBus.BehaviorChain1.InvokeNext(T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107\r\n at NServiceBus.BehaviorChain1.<>c__DisplayClass5.<InvokeNext>b__2() in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Pipeline\\BehaviorChain.cs:line 95\r\n at NServiceBus.SubscriptionReceiverBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Unicast\\Subscriptions\\MessageDrivenSubscriptions\\SubscriptionReceiverBehavior.cs:line 32\r\n at NServiceBus.BehaviorChain1.InvokeNext(T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107\r\n at NServiceBus.BehaviorChain1.<>c__DisplayClass5.<InvokeNext>b__2() in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Pipeline\\BehaviorChain.cs:line 95\r\n at NServiceBus.UnitOfWorkBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\UnitOfWork\\UnitOfWorkBehavior.cs:line 42\r\n at NServiceBus.BehaviorChain1.InvokeNext(T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107\r\n at NServiceBus.BehaviorChain1.<>c__DisplayClass5.<InvokeNext>b__2() in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Pipeline\\BehaviorChain.cs:line 95\r\n at NServiceBus.ChildContainerBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Unicast\\Behaviors\\ChildContainerBehavior.cs:line 17\r\n at NServiceBus.BehaviorChain1.InvokeNext(T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107\r\n at NServiceBus.BehaviorChain1.<>c__DisplayClass5.<InvokeNext>b__2() in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Pipeline\\BehaviorChain.cs:line 95\r\n at NServiceBus.ProcessingStatisticsBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Monitoring\\ProcessingStatisticsBehavior.cs:line 23\r\n at NServiceBus.BehaviorChain1.InvokeNext(T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107\r\n at NServiceBus.BehaviorChain1.<>c__DisplayClass5.<InvokeNext>b__2() in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Pipeline\\BehaviorChain.cs:line 95\r\n at NServiceBus.AuditBehavior.Invoke(IncomingContext context, Action next) in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Audit\\AuditBehavior.cs:line 20\r\n at NServiceBus.BehaviorChain1.InvokeNext(T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\BehaviorChain.cs:line 107\r\n at NServiceBus.BehaviorChain1.Invoke() in c:\\BuildAgent\\work\\3206e2123f54fce4\\src\\NServiceBus.Core\\Pipeline\\BehaviorChain.cs:line 58\r\n at NServiceBus.Pipeline.PipelineExecutor.Execute[T](BehaviorChain1 pipelineAction, T context) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Pipeline\PipelineExecutor.cs:line 129\r\n at NServiceBus.Unicast.Transport.TransportReceiver.ProcessMessage(TransportMessage message) in c:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Unicast\Transport\TransportReceiver.cs:line 328",

      "NServiceBus.FailedQ": "<<Queue,
      "NServiceBus.TimeOfFailure": "2015-07-06 02:52:26:254996 Z"

Here's the message class as requested... Originally there were 3 different "Infos" in the message, but tried to simplify, so now only the permission info in in the event...

  public class CredentialPermissionGrantedEvent : IEvent
    {
        public PermissionInfo Permission { get; set; }
    }    

public class PermissionInfo
    {
        public Guid PermissionReference { get; set; }
        public DateTime ActivationDate { get; set; }
        public Guid CredentialReference { get; set; }
        public Guid DeviceReference { get; set; }
        public DateTime ExpirationDate { get; set; }
        public string Function { get; set; }
        public Guid ScheduleReference { get; set; }
        public long Timestamp { get; set; }
    }

Any assistance will be greatly appreciated

  • Paul
2
Share your message class with us, Also, try using Xml serialization instead of Json, just to see if it will work.Alexey Zimarev
Original Post has message class(es) added. Will try XML serializer, thanksPaul Heal
Further points... If I manually drop the messages from the error queue into the subscription Queue the message is handled correctly.Paul Heal
We had issues earlier with Json and Azure SB queues. Yves explained that we should use xml and json was not supported. I am not sure if this has changed but pls let me know what happens if you use xml serializer. Try omitting direct serializer specification, assuming the default one will be used.Alexey Zimarev
Any luck with this issue? what was the solution? getting the same errorMike

2 Answers

0
votes

Looks like json.net is deserializing your message to a JObject instead of your message's type, do both endpoints know about the same type? If you look at the message body, is the necessary json.net metadata ($type) included?

0
votes
  • ServiceControl adds its callback address header (it happens in SQLServer and RabbitMQ transports) to the message when sending it for re-processing
  • The handler when it processes the message calls Bus.Reply or Bus.Return
  • The reply gets routed to SC callback queue instead of the actual destination (which was set in the reply to field)

Find more guides here