question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Signalr not serialize correctly CustomNotificationData

See original GitHub issue

I create a custom notification data

[Serializable]
    public class NewMessage: NotificationData
    {
        public string Data { get; set; }
        public bool IsRequired { get; set; }
        public NewMessage()
        {

        }
        public NewMessage(string data,bool isRequired)
        {
            Data = data;
            IsRequired = isRequired;
        }
}

I send it using the NotificationPublisher

var body = new NewMessage("test data with boolean", true);
NotificationPublisher.PublishAsync(notificationName, body, null, NotificationSeverity.Info, new List<Abp.UserIdentifier> { new Abp.UserIdentifier(tenantId, userId) }.ToArray())

but when I receive the message in signalR it comes in this form

{
	"type": 1,
	"target": "getNotification",
	"arguments": [{
			"tenantId": 1,
			"userId": 2,
			"state": 0,
			"notification": {
				"tenantId": 1,
				"notificationName": "NewMessage",
				"data": {
					"type": "Project.RealTime.Notifications.NewMessage",
					"properties": {}
				},
				"entityType": null,
				"entityTypeName": null,
				"entityId": null,
				"severity": 0,
				"creationTime": "2021-03-10T07:27:45.3992987-05:00",
				"id": "dfdca5d9-fddf-4962-a8d1-c75fad6fc2b1"
			},
			"id": "057a5037-5e33-4f97-ab30-8dfcbac6921e"
		}
	]
}

i check the notification on db and has the field Data and IsRequired without problem notification on bd

this app is using Abp 6.2.0 and Net core 5, and postgresql database but I have the same code in another app on abp 5.14.0 and does not have this problem

thanks for your help

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
acjhcommented, Mar 12, 2021

This is caused by SignalR using System.Text.Json since ASP.NET Core 3.0.

You can switch to Newtonsoft.Json:

  1. Install the Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson NuGet package.
  2. Chain an AddNewtonsoftJsonProtocol method call to the AddSignalR method call in Startup.ConfigureServices:
services.AddSignalR()
        .AddNewtonsoftJsonProtocol();

https://docs.microsoft.com/en-us/aspnet/core/signalr/configuration?view=aspnetcore-5.0&tabs=dotnet#switch-to-newtonsoftjson

0reactions
ddo88commented, Mar 12, 2021

@acjh you are the best, that work’s for me thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR not serializing/deserializing custom DataMember ...
One possible solution is to switch the serialization engine to Newtonsoft's JSON implementation, as suggested in @Aleksandr Albert's answer.
Read more >
ASP.NET Core SignalR custom serialization
I want to transmit data between client and server and vice versa using a custom serializer, and not using the default JSON option....
Read more >
Can't serialize poco class · Issue #64
I'm sening a POCO with a SignalR hub then, it gets sent to my subscribed client, but the data is lost. The data...
Read more >
Real time notification system
Introduction. Notifications are used to inform users on specific events in the system. ASP.NET Boilerplate provides a pub/sub ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found