Cannot access child value on Newtonsoft.Json.Linq.JValue

7,330 views
Skip to first unread message

Ross

unread,
Aug 11, 2010, 3:55:07 PM8/11/10
to ncqrs-dev
I am getting this error while trying to store an event. It is a
straight forward object, not sure what I am doing wrong. Have you seen
this before?

Stack trace below:

at Newtonsoft.Json.Linq.JToken.Children()
at
Newtonsoft.Json.Linq.JToken.System.Collections.Generic.IEnumerable<Newtonsoft.Json.Linq.JToken>.GetEnumerator()
at
Newtonsoft.Json.Linq.JToken.System.Collections.IEnumerable.GetEnumerator()
at MongoDB.Driver.Bson.BsonWriter.CalculateSize(IEnumerable arr)
at MongoDB.Driver.Bson.BsonWriter.CalculateSize(Object val)
at MongoDB.Driver.Bson.BsonWriter.CalculateSize(IEnumerable arr)
at MongoDB.Driver.Bson.BsonWriter.CalculateSize(Object val)
at MongoDB.Driver.Bson.BsonWriter.CalculateSize(IEnumerable arr)
at MongoDB.Driver.Bson.BsonWriter.CalculateSize(Object val)
at MongoDB.Driver.Bson.BsonWriter.CalculateSize(Document doc)
at MongoDB.Driver.Protocol.InsertMessage.ChunkMessage(BsonWriter
writer)
at MongoDB.Driver.Protocol.InsertMessage.Write(Stream stream)
at
MongoDB.Driver.Connections.Connection.SendMessage(IRequestMessage msg)
at MongoDB.Driver.Collection.Insert(IEnumerable`1 docs)
at MongoDB.Driver.Collection.Insert(IEnumerable`1 docs, Boolean
safemode)
at
Ncqrs.Eventing.Storage.MongoDB.MongoDBEventStore.Save(EventSource
source)
at Ncqrs.Domain.DomainRepository.Save(AggregateRoot aggregateRoot)
at Ncqrs.Domain.UnitOfWork.Accept()
at
Ncqrs.CommandExecution.AutoMapping.Actions.DirectMethodAction.Execute(ICommand
command)
at
Ncqrs.CommandExecution.AutoMapping.AutoMappingCommandExecutor`1.Execute(T
command)
at
Ncqrs.CommandExecution.CommandExecutorBase`1.Ncqrs.CommandExecution.ICommandExecutor.Execute(ICommand
command)
at
Ncqrs.CommandExecution.CommandExecutionDispatcher.Execute(ICommand
command)
at Platform.Tests.Program.Main(String[] args) in C:\Data\Projects
\Personal\GM\trunk\Platform\Platform.Tests\Program.cs:line 42
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Pieter Joost van de Sande

unread,
Aug 12, 2010, 2:30:52 AM8/12/10
to ncqr...@googlegroups.com
Can you post the class definition of the event?

PJ

Ross

unread,
Aug 12, 2010, 2:24:55 PM8/12/10
to ncqrs-dev
Sure, as follows:

public class SizeAdded : IEvent
{
public Guid ItemId { get; set; }

public Size Size { get; set; }
}

[Serializable]
public class Size
{
public Size()
{
Prices = new List<Price>();
}

public string Designation { get; set; }

public int Qty { get; set; }

public List<Price> Prices { get; set; }
}

[Serializable]
public class Price
{
public decimal Amount { get; set; }
}

Thanks




On Aug 12, 8:30 am, Pieter Joost van de Sande <p...@born2code.net>
wrote:
> Can you post the class definition of the event?
>
> PJ
>
>
>
> On Wed, Aug 11, 2010 at 9:55 PM, Ross <rossjayjo...@gmail.com> wrote:
> > I am getting this error while trying to store an event. It is a
> > straight forward object, not sure what I am doing wrong. Have you seen
> > this before?
>
> > Stack trace below:
>
> >   at Newtonsoft.Json.Linq.JToken.Children()
> >   at
>
> > Newtonsoft.Json.Linq.JToken.System.Collections.Generic.IEnumerable<Newtonso ft.Json.Linq.JToken>.GetEnumerator()

Pieter Joost van de Sande

unread,
Aug 12, 2010, 6:16:26 PM8/12/10
to ncqrs-dev
I was digging in the JSon event serialization we use, I could repro the exception. After looking better to the stacktrace I see this error is coming from the MongoDB driver while it tries to serialize to BSon. On the first hand, I can see any unusual code that could cause this, but I'll try to repro it with MongoDB after a good night of sleep :)

Just curious, why do you use Mongo?

Ross

unread,
Aug 13, 2010, 2:20:06 AM8/13/10
to ncqrs-dev
Hi Pieter,

Correct, it is coming from the Mongo Driver. I am using it only
because Ncqrs comes out the box with it :p I am thinking about using
Raven DB as the event store, do you think this would be a good fit?
For the time being I have implemented an in memory event store for
experimenting with Ncqrs

Thanks

On Aug 13, 12:16 am, Pieter Joost van de Sande <p...@born2code.net>
wrote:

Pieter Joost van de Sande

unread,
Aug 13, 2010, 2:40:33 AM8/13/10
to ncqr...@googlegroups.com
Cool! Is the in memory one worth sharing? And for the choice of an event store, RavenDB has better transaction support then MongoDB.

* Verstuurd vanaf de iPhone

Ross

unread,
Aug 13, 2010, 2:52:04 AM8/13/10
to ncqrs-dev
Not sure if it's worth sharing or not but here it is any way :p It was
built just to get things going so the implementation is very
simplistic. I will share the Raven DB event store when I get it
finished.

public class InMemoryEventStore : IEventStore
{
private readonly Dictionary<Guid, List<HistoricalEvent>>
_events = new Dictionary<Guid, List<HistoricalEvent>>();

public IEnumerable<HistoricalEvent>
GetAllEventsForEventSource(Guid id)
{
return _events[id];
}

public IEnumerable<IEvent> Save(EventSource source)
{
if (!_events.ContainsKey(source.Id) || _events[source.Id]
== null)
_events[source.Id] = new List<HistoricalEvent>();
var events = source.GetUncommitedEvents();
events.ToList().ForEach(e => _events[source.Id].Add(new
HistoricalEvent(DateTime.Now, e)));
return events;
}
}

On Aug 13, 8:40 am, Pieter Joost van de Sande
<pjvandesa...@born2code.net> wrote:
> Cool! Is the in memory one worth sharing? And for the choice of an event store, RavenDB has better transaction support then MongoDB.
>
> * Verstuurd vanaf de iPhone
>
Reply all
Reply to author
Forward
0 new messages