Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6472289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:19:33+00:00 2026-05-25T06:19:33+00:00

I am running into a base-typing problem with messages I am attempting to publish

  • 0

I am running into a base-typing problem with messages I am attempting to publish through MassTransit. Consider the following:

[Serializable]
public abstract class Event : CorrelatedBy<Guid> {

    public Guid CorrelationId { get; set; }

    public abstract string EventName { get; }

    public override string ToString() {
        return string.Format("{0} - {1}", EventName, CorrelationId);
    }

}

[Serializable]
public class PersonCreated : Event {

    public PersonCreated(Guid personId, string firstName, string lastName) {

       PersonId = personId;
       FirstName = firstName;
       LastName = lastName;

    }

    public readonly Guid PersonId;
    public readonly string FirstName;
    public readonly string LastName;

}

However, when I attempt to publish a collection of abstract events with something like:

public void PublishEvents(IEnumerable<Event> events) {

    foreach (var e in events) {

        Bus.Instance.Publish(e);

    }

}

I do NOT receive any events out of this collection, regardless of their concrete types. If I cast the event to its proper concrete type before publishing on the bus, I do receive the message properly.

Any ideas as to how I can correct this to allow my abstract collection of Events to be processed without casting each one?

EDIT: I have attempted to change my settings to use BinarySerialization like so:

 Bus.Initialize(sbc =>
     {
         sbc.UseBinarySerializer();
     });

and have not yielded any change in behavior. The only way that I have been able to get my Consumes<PersonCreated> class to be called is to explicitly cast an event to PersonCreated type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:19:34+00:00Added an answer on May 25, 2026 at 6:19 am

    Edit: Serializer doesn’t matter here. I didn’t think this through.

    You could invoke Bus.Instance.Publish with the right type information by doing reflection on the Event object and getting it’s actual type as well. This is going to be some awkward code but once it’s done likely easy to reuse. In Magnum we have an extension method to help with this.

    Bus.Instance.FastInvoke(new[]{ event.GetType() }, "Publish", event);
    

    Join us on the mailing list, http://groups.google.com/group/masstransit-discuss, and we’ll be happy to discuss in more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running into ActiveRecord::ConnectionNotEstablished error. I have the following code ActiveRecord::Base.establish_connection(:adapter => 'sqlite3',
I'm attempting to build/install Cabal on my system and I'm running into the following
I'm running into a small problem attempting to have an animation stopped mid-animation gracefully
Running into a problem. I have a table defined to hold the values of
EDIT: I am basically running into the following documented issue . I am using
I'm running into a problem when trying to select records from my 2005 MS-SQL
Greetings folks! I'm running into a problem with WPF databinding that I hope you
im running into this problem as i try to run a piece of django
I am currently running into a problem of connecting one model to another. Basically
I am running into a problem where my CRUD operations on an entity sourced

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.