title: MassTransit messages types must not be System types exception
body: <p>I'm pretty new to MassTransit and don't understand what am I doing wrong to get the following exception: <code>Messages types must not be System types</code>.</p>
  <p>Here are my definitions:</p>
  <pre><code>[BsonIgnoreExtraElements]
  public class ArcProcess : SagaStateMachineInstance, ISagaVersion
  {
      public Guid CorrelationId { get; set; }
  
      public string CurrentState { get; set; }
  
      public int Version { get; set; }
  
      public Guid ActivationId { get; set; }
  }
  
  public static class MessageContracts
  {
      static bool _initialized;
  
      public static void Initialize()
      {
          if (_initialized)
              return;
  
          GlobalTopology.Send.UseCorrelationId&lt;StartProcessingMessage&gt;(x =&gt; x.ActivationId);
          GlobalTopology.Send.UseCorrelationId&lt;ReconstructionFinishedMessage&gt;(x =&gt; x.ActivationId);
          GlobalTopology.Send.UseCorrelationId&lt;ProcessingFinishedMessage&gt;(x =&gt; x.ActivationId);
  
          _initialized = true;
      }
  }
  </code></pre>
  <p>2 of my consumers are:</p>
  <pre><code>public class StartReconstructionConsumer : IConsumer&lt;StartProcessingMessage&gt;
  {
      readonly ILogger&lt;StartReconstructionConsumer&gt; _Logger;
  
      private readonly int _DelaySeconds = 5;
  
      public StartReconstructionConsumer(ILogger&lt;StartReconstructionConsumer&gt; logger)
      {
          _Logger = logger;
      }
  
      public async Task Consume(ConsumeContext&lt;StartProcessingMessage&gt; context)
      {
          var activationId = context.Message.ActivationId;
  
          _Logger.LogInformation($&quot;Received Scan: {activationId}&quot;);
  
          await Task.Delay(_DelaySeconds * 1000);
  
          _Logger.LogInformation($&quot;Finish Scan: {activationId}&quot;);
  
          await context.Publish&lt;ReconstructionFinishedMessage&gt;(new { ActivationId = activationId });
      }
  }
  
  public class ProcessingFinishedConsumer : IConsumer&lt;ProcessingFinishedMessage&gt;
  {
      readonly ILogger&lt;ProcessingFinishedConsumer&gt; _Logger;
  
      public ProcessingFinishedConsumer(ILogger&lt;ProcessingFinishedConsumer&gt; logger)
      {
          _Logger = logger;
      }
  
      public async Task Consume(ConsumeContext&lt;ProcessingFinishedMessage&gt; context)
      {
          _Logger.LogInformation($&quot;Finish {context.Message.ActivationId}&quot;);
  
          await Task.CompletedTask;
      }
  }
  </code></pre>
  <p>And here is the StateMachine definition:</p>
  <pre><code>public class ArcStateMachine: MassTransitStateMachine&lt;ArcProcess&gt;
  {
      static ArcStateMachine()
      {
          MessageContracts.Initialize();
      }
  
      public ArcStateMachine()
      {
          InstanceState(x =&gt; x.CurrentState);
  
          Initially(
              When(ProcessingStartedEvent)
              .Then(context =&gt;
              {
                  Console.WriteLine(&quot;&gt;&gt; ProcessingStartedEvent&quot;);
                  context.Instance.ActivationId = context.Data.ActivationId;
              })
              .TransitionTo(ProcessingStartedState));
  
          During(ProcessingStartedState,
              When(ReconstructionFinishedEvent)
              .Then(context =&gt;
              {
                  Console.WriteLine(&quot;&gt;&gt; ReconstructionFinishedEvent&quot;);
                  context.Instance.ActivationId = context.Data.ActivationId;
              })
              .Publish(context =&gt;
              {
                  return context.Init&lt;ProcessingFinishedMessage&gt;(new { ActivationId = context.Data.ActivationId });
              })
              .TransitionTo(ProcessingFinishedState)
              .Finalize());
      }
  
      public State ProcessingStartedState { get; }
      public State ReconstructionStartedState { get; }
      public State ReconstructionFinishedState { get; }
      public State ProcessingFinishedState { get; }
  
      public Event&lt;StartProcessingMessage&gt; ProcessingStartedEvent { get; }
      public Event&lt;ReconstructionStartedMessage&gt; ReconstructionStartedEvent { get; }
      public Event&lt;ReconstructionFinishedMessage&gt; ReconstructionFinishedEvent { get; }
      public Event&lt;ProcessingFinishedMessage&gt; ProcessingFinishedEvent { get; }
  }
  </code></pre>
  <p>And the setup for MassTransit looks the following:</p>
  <pre><code>var rabbitHost = Configuration[&quot;RABBIT_MQ_HOST&quot;];
  
          if (rabbitHost.IsNotEmpty())
          {
              services.AddMassTransit(cnf =&gt;
              {
                  var connectionString = Configuration[&quot;MONGO_DB_CONNECTION_STRING&quot;];
  
                  var machine = new ArcStateMachine();
                  var repository = MongoDbSagaRepository&lt;ArcProcess&gt;.Create(connectionString,
                      &quot;mongoRepo&quot;, &quot;WorkflowState&quot;);
  
                  cnf.AddConsumer(typeof(StartReconstructionConsumer));
                  cnf.AddConsumer(typeof(ProcessingFinishedConsumer));
  
                  cnf.UsingRabbitMq((context, cfg) =&gt;
                  {
                      cfg.Host(new Uri(rabbitHost), hst =&gt;
                      {
                          hst.Username(&quot;guest&quot;);
                          hst.Password(&quot;guest&quot;);
                      });
  
                      cfg.ConfigureEndpoints(context);
  
                      cfg.ReceiveEndpoint(BusConstants.SagaQueue,
                          e =&gt; e.StateMachineSaga(machine, repository));
                  });
              });
  
              services.AddMassTransitHostedService();
  
              services.AddSwaggerGen(c =&gt;
              {
                  c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;MyApp&quot;, Version = &quot;v1&quot; });
              });
          }
  </code></pre>
  <p>I have several questions about it:</p>
  <ol>
  <li><p>When actually the event is published as a result of publishing a message? I.e. in my example <code>await _BusInstance.Bus.Publish&lt;StartProcessingMessage&gt;(new { ActivationId = id });</code> is called from a WebApi which is consumed by <code>StartReconstructionConsumer</code> but when actually the state machine starts to act with <code>Initially(When(ProcessingStartedEvent)...</code>?</p>
  </li>
  <li><p>My processing should ensure I'm already in the <code>ProcessingStartedState</code> state in order to <code>During(ProcessingStartedState, When(ReconstructionFinishedEvent)...</code> to act correctly. So how do I ensure that my consumer that fires upon receive of <code>StartProcessingMessage</code> can publish the <code>ReconstructionFinishedMessage</code> that should initiate that <code>During</code>? Am I building the messages exchange correctly?</p>
  </li>
  <li><p>Currently for the <code>await context.Publish&lt;ReconstructionFinishedMessage&gt;(new { ActivationId = activationId });</code> I get an exception in the logs that states <code>R-FAULT rabbitmq://localhost/saga.service d4070000-7b3b-704d-0f10-08d99942c959 Nanox.GC.Shared.AppCore.Messages.ReconstructionFinishedMessage ReconCaller.Saga.ArcProcess(00:00:04.1132604)</code> while that guid in the message is actually the <code>MessageId</code>. And my message in the rabbitmq is routed to <code>saga.service_error</code> with an exception <code>Messages types must not be System types: System.Threading.Tasks.Task&lt;Nanox.GC.Shared.AppCore.Messages.ProcessingFinishedMessage&gt; (Parameter 'T')</code>.</p>
  </li>
  </ol>
  <p>It seems like I'm missing here really big..</p>
  <p>My intent is to initiate processing that will have several stages processed by a few consumers sequentially. So here I tried to build a simple StateMachine that starts whenever someone called <code>StartProcessing</code>, then each consumer will do its job and fire the <code>FinishedStepX</code> which will promote the state machine to a new step and initiate the next consumer up until all the processing is done and the state machine will report <code>ProcessingComplete</code>.</p>
  <p>Thanks for any help n advance</p>