Open Closed

HandleEventAsync JsonReaderException #9962


User avatar
0
samirmustafayev created

Hi Abp Team,

I am getting a JsonException when Project A publishes events to Project B. We are using RabbitMQ for event exchange. In the local environment, which is Windows, it works, but when published to Ubuntu, JsonExceptions are thrown. Below is the JsonException that was thrown: ↓

<b>How can i solve this issue?</b>


8 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    • The JsonReaderException you are encountering ('{' is an invalid start of a property name. Expected a '\"'.) typically indicates that the event payload being deserialized is not valid JSON. This often happens when the message is sent as plain text or another format (such as single-quoted JSON or a .NET object string) instead of standard double-quoted JSON.

    • Since it works on Windows but fails on Ubuntu, the most common causes are:

      1. Inconsistent serialization settings between environments (e.g., using Newtonsoft.Json in one place and System.Text.Json in another).
      2. Locale or encoding differences (e.g., line endings, UTF-8/UTF-16).
      3. RabbitMQ message content-type or encoding differences.

    How to Solve

    1. Ensure Consistent Serialization

      • Make sure both Project A (publisher) and Project B (consumer) use the same JSON serializer (preferably System.Text.Json for ABP v7+).
      • Do not manually serialize/deserialize events; let ABP's distributed event bus handle it.
    2. Check for Manual Serialization

      • If you are manually serializing the event before publishing, remove that code. Publish the event object directly:
    await _distributedEventBus.PublishAsync(new MyEventEto { ... });
    
    • Do not use JsonConvert.SerializeObject or similar before publishing.
    1. Check RabbitMQ Message Content-Type

      • Ensure the message is published with content-type: application/json.
      • If you are using custom RabbitMQ code, set the content type explicitly.
    2. Check for OS-Specific Differences

      • Make sure the .NET runtime and all dependencies are the same version on both Windows and Ubuntu.
      • Check for any environment-specific configuration differences.
    3. Clear Old Queues

      • If you changed the event type or serialization, old messages in RabbitMQ may still be in the wrong format. Purge the relevant queues/exchanges in RabbitMQ to remove incompatible messages.
    4. Review Event Contracts

      • Ensure the event class (ETO) is identical in both projects (namespace, property names, etc.).

    References

    These steps should help you resolve the cross-platform serialization issue with ABP distributed events and RabbitMQ.


    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share your event class?

    It seems that there is an issue with the data in the database.

    Please also share the code of MaintenanceRequestClosedEventHandler.cs

    Thanks

  • User Avatar
    0
    samirmustafayev created

    Yes , here is the event class

    [EventName("Maintenance.Request.Closed")]
    public class MaintenanceRequestClosedEto
    {
        public Guid Id { get; set; }
    
        public DateTime ClosedDate { get; set; }
    }
    

    and methode that handles event

    public async Task HandleEventAsync(MaintenanceRequestClosedEto eventData)
     {
         var entity = await _repository.FindAsync(eventData.Id);
         entity.SetStatus(MaintenanceRequestStatus.Completed, eventData.ClosedDate);
         await _repository.UpdateAsync(entity);
     }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you check the entity data in the database with eventData.Id?

    Key focus on the ExtraProperties property.

    Thanks.

  • User Avatar
    0
    samirmustafayev created

    Yes, in the _repository, for different eventData.Id in ExtraProperties has different values - some are {}, some are {{}}, and some are null.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    {} and null is no problem.

    But {{}} is wrong.

    Do you remember why {{}} is write to database? Can you share some code?

    Thanks.

  • User Avatar
    0
    samirmustafayev created

    We solved the issue by updating ExtraProperties to {}. Do you remember why {{}} was written to the database? We are looking into it, and if any questions come up, we will ask.

    Thank you for the fast response.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on October 02, 2025, 08:00