Exception receiving message with collection having single element

443 views
Skip to first unread message

Krzysztof Kozmic

unread,
Aug 25, 2011, 11:44:13 PM8/25/11
to masstransit-discuss
I have message type that has collection of int ids in it.

In particular a single id is being sent, but when receiving the
following exception occurs. I'm running nuget 2.0.0.4 version.

It seems to be a serializer bug, so is there a way to switch to a
different serializer? (binary, xml, whatever that works?)

2011-08-26 13:38:47,238 [12] ERROR MassTransit.Context.ReceiveContext
[(null)] - Exception converting message to type:
SendPrintCorrespondence
System.Runtime.Serialization.SerializationException: Failed to
deserialize the message --->
Newtonsoft.Json.JsonSerializationException: Error converting value
"25" to type 'System.Collections.Generic.IEnumerable`1[System.Int32]'.
---> System.Exception: Could not cast or convert from System.String to
System.Collections.Generic.IEnumerable`1[System.Int32]. at
Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object
value, Type initialType, Type targetType) in d:\Home\json.net\Src
\Newtonsoft.Json\Utilities\ConvertUtils.cs:line 467
at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object
initialValue, CultureInfo culture, Type targetType) in d:\Home\json.net
\Src\Newtonsoft.Json\Utilities\ConvertUtils.cs:line 389
at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(Object
value, CultureInfo culture, Type targetType) in d:\Home\json.net\Src
\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 94
--- End of inner exception stack trace ---
at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(Object
value, CultureInfo culture, Type targetType) in d:\Home\json.net\Src
\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line
498
at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader
reader, Type objectType, JsonContract contract, JsonProperty member,
Object existingValue) in d:\Home\json.net\Src\Newtonsoft.Json
\Serialization\JsonSerializerInternalReader.cs:line 244
at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueProperty(JsonReader
reader, JsonProperty property, Object target, Boolean
gottenCurrentValue, Object currentValue) in d:\Home\json.net\Src
\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line
199
at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty
property, JsonReader reader, Object target) in d:\Home\json.net\Src
\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line
567
at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object
newObject, JsonReader reader, JsonObjectContract contract, String id)
in d:\Home\json.net\Src\Newtonsoft.Json\Serialization
\JsonSerializerInternalReader.cs:line 1057
at
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader
reader, Object target) in d:\Home\json.net\Src\Newtonsoft.Json
\Serialization\JsonSerializerInternalReader.cs:line 87
at Newtonsoft.Json.JsonSerializer.PopulateInternal(JsonReader
reader, Object target) in d:\Home\json.net\Src\Newtonsoft.Json
\JsonSerializer.cs:line 367
at Newtonsoft.Json.JsonSerializer.Populate(JsonReader reader,
Object target) in d:\Home\json.net\Src\Newtonsoft.Json
\JsonSerializer.cs :line 358
at
MassTransit.Serialization.JsonMessageTypeConverter.<>c__DisplayClass4`1.<TryConvert>b__1(JsonReader
jsonReader) in d:\BuildAgent-03\work\8d1373c869590c5b\src\MassTransit
\Serialization\JsonMessageTypeConverter.cs:line 65
at
MassTransit.Serialization.JsonMessageTypeConverter.UsingReader(Action`1
callback) in d:\BuildAgent-03\work\8d1373c869590c5b\src\MassTransit
\Serialization\JsonMessageTypeConverter.cs:line 87
at MassTransit.Serialization.JsonMessageTypeConverter.TryConvert[T]
(T& message) in d:\BuildAgent-03\work\8d1373c869590c5b\src\MassTransit
\Serialization\JsonMessageTypeConverter.cs:line 65
at MassTransit.Context.ReceiveContext.TryGetContext[T]
(IConsumeContext`1& context) in d:\BuildAgent-03\work\8d1373c869590c5b
\src\MassTransit\Context\ReceiveContext.cs:line 149
--- End of inner exception stack trace ---

Travis Smith

unread,
Aug 26, 2011, 8:20:58 AM8/26/11
to masstrans...@googlegroups.com
http://readthedocs.org/docs/masstransit/en/latest/configuration/config_api.html#serializer-options

This appears to be a bug with Newtonsoft's JSON serialization code.
I'd consider submitting a bug report with them if you can easily
duplicate this outside of MassTransit.

I hope this helps.

-Travis

> --
> You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
> To post to this group, send email to masstrans...@googlegroups.com.
> To unsubscribe from this group, send email to masstransit-dis...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.
>
>

Chris Patterson

unread,
Aug 26, 2011, 11:35:36 AM8/26/11
to masstrans...@googlegroups.com
What is the type of the collection?

Because I know it works with IList, IDictionary, and straight int[] types.

Taliesin Sisson

unread,
Dec 1, 2011, 4:21:59 AM12/1/11
to masstrans...@googlegroups.com
http://json.codeplex.com/SourceControl/list/patches
ID: 10926

I have submitted a patch that should take care of all collections with 0 or 1 elements in it. I have tested it against a variety of custom and standard collection types. As an added bonus it supports ExpandoObjects and correctly deserializing child property types. We could probably get rid of ListJsonConverter if the patch makes it in.

It should work fine with 0 or 1 sized int[] as this is the problem I was running into.
Reply all
Reply to author
Forward
0 new messages