pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
747 stars 144 forks source link

Subscribing in a different project than publishing, skipping strict type checks #371

Open carol-braileanu opened 6 years ago

carol-braileanu commented 6 years ago

I have a subscriber in a .NET core project, listening for an object called Notification. I have a publisher that must be in a .NET 4.6 project. I copied the Notification contract from .NET Core to .NET, and I tried to publish it to the queue. The Notification classes in both projects are identical, and my code is:

queuingService.BusClient.PublishAsync(not, Guid.NewGuid(), cfg => { cfg.WithExchange(e => e.WithName("flowconcept.domaincontracts")); cfg.WithRoutingKey("notification.#"); }).Wait();

However, I am running into a JSON serialization error:

Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON 'FlowConcept.DomainContracts.Notification, DeltaStore.Core'. Path '$type', line 1, position 78. ---> System.IO.FileNotFoundException: Could not load file or assembly 'DeltaStore.Core, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

Is there a way to disable these strict type checks?

pardahlman commented 6 years ago

Hello - yes! By default TypeNameHandling.Auto is used. From the official documentation

Include the .NET type name when the type of the object being serialized is not the same as its declared type

If this doesn't work for you, you could explicitly register a serializer in RawRabbit with TypeNameHandling.None and you should be good to go.