Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherited interface messages won't process if conventions is used and handler only exists for base message #4567

Closed
janovesk opened this issue Mar 22, 2017 · 8 comments
Assignees
Labels
Milestone

Comments

@janovesk
Copy link
Contributor

janovesk commented Mar 22, 2017

Problem

The combination of

  1. An interface based message inheriting another interface based message
  2. Convention based definition of events
  3. JsonSerializer

does not work correctly. :(

If you publish a interface based message that inherits from another interface based message, a subscriber of the base message will blow up with a deserialization message stating that it can not instanciate the inherited type at publish time.

Changing to the xmlserializer, removing the inheritance, using classes instead of interfaces or inheriting from IEvent fixes the problem.

Repro

Originally reported by user. Repro available here.

Code highlights

namespace Event
{
    public interface IBaseEvent
    {
        Guid Id { get; set; }
    }

    public interface IInheritedEvent : IBaseEvent
    {
    }
}
endpointConfiguration.UseSerialization<JsonSerializer>();
endpointConfiguration.Conventions().DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Event"));
public class BaseEventHandler : IHandleMessages<IBaseEvent>
{
    public Task Handle(IBaseEvent message, IMessageHandlerContext context)
    {
        return Task.CompletedTask;
    }
}

Error message on subscriber receiving IInheritedEvent

2017-03-22 14:12:14.799 ERROR NServiceBus.RecoverabilityExecutor Moving message '64e5a7f3-1092-480f-818b-a73e00d9974f' to the error queue 'error' because processing failed due to an exception:
NServiceBus.MessageDeserializationException: An error occurred while attempting to extract logical messages from transport message 64e5a7f3-1092-480f-818b-a73e00d9974f ---> Newtonsoft.Json.JsonSerializationException: Could not create an instance of type Event.IInheritedEvent. Type is an interface or abstract class and cannot be instantiated. Path 'Id', line 1, position 6.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Transports\MessageContext.cs:line 0
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Transports\MessageContext.cs:line 0
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) in C:\BuildAgent\work\3206e2123f54fce4\src\NServiceBus.Core\Transports\MessageContext.cs:line 0
..
@janovesk
Copy link
Contributor Author

Possibly related to #4452

@timbussmann
Copy link
Contributor

@Particular/nservicebus-maintainers does this qualify as critical?
@janovesk are you investigating further on this issue?

@andreasohlund
Copy link
Member

Talking this through with @timbussmann we decided to not rush the fix for this into 6.2 since its to risky.

The user have a workaround for now and the bug would be found during development. Assigning this to 6.3 since we still believe this needs to be addressed

@andreasohlund andreasohlund changed the title Interface based message inheritance, conventions and json serializer does not play well together Inherited interface messages won't process if conventions is used and handler only exists for base message Apr 21, 2017
@mluttrell
Copy link

@andreasohlund any idea when we can expect this? We're in the process of upgrading to NSB6 and running into this in a number of places.

@andreasohlund
Copy link
Member

andreasohlund commented Apr 26, 2017

My best guestimate is that 6.3.0 will be released end of next week. Does that align with your deadline?

@mluttrell
Copy link

That general timeframe should be fine for us. Thank you!

@praveenkonduru
Copy link

I am running through the same issue. what is the work around for the issue

@timbussmann
Copy link
Contributor

@praveenkonduru we recommend to upgrade to NServiceBus 6.3 or higher. Those versions should resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment