Unable to cast object of type 'Raven.Database.Linq.DynamicJsonObject' to type '*****'.

1,163 views
Skip to first unread message

jim

unread,
Feb 10, 2011, 3:48:12 AM2/10/11
to ravendb
Hi

I query the list from ravendb, it throw the exception:

Message: "System.InvalidCastException: Unable to cast object of type
'Raven.Database.Linq.DynamicJsonObject' to type '******'."


Error Stack Trace:

Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity[T]
(String id, JObject documentFound, JObject metadata) in c:\Builds\raven
\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs: line 391
Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity[T]
(String key, JObject document, JObject metadata) in c:\Builds\raven
\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs: line 318
Raven.Client.Document.AbstractDocumentQuery`2.Deserialize(JObject
result) in c:\Builds\raven\Raven.Client.Lightweight\Document
\AbstractDocumentQuery.cs: line 1221
System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
Raven.Client.Document.AbstractDocumentQuery`2.GetEnumerator() in c:
\Builds\raven\Raven.Client.Lightweight\Document
\AbstractDocumentQuery.cs: line 440
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
Kooboo.CMS.Content.Persistence.RavenDB.Embedded.Tests.InsertUpdateDeleteTests.Export_Schema_Data()
in E:\Projects\Kooboo\src\trunk\Kooboo.CMS\Kooboo.CMS.Content
\Kooboo.CMS.Content.Persistence.RavenDB.Embedded.Tests
\InsertUpdateDeleteTests.cs: line 106


The entity type inherited from DynamicObject and implements
IDictionary<string, object> interface. I have no idea if it is a bug.

The exception throwed in both "RavenDB-Build-206" and "RavenDB-
Build-264".

Thanks.

Matt Warren

unread,
Feb 10, 2011, 4:28:59 AM2/10/11
to ravendb
Can you post the code you are using, so that we can reproduce the
problem?

jim

unread,
Feb 10, 2011, 5:04:26 AM2/10/11
to ravendb
HI

Sent the test project to your gmail.

Ayende Rahien

unread,
Feb 10, 2011, 5:08:05 AM2/10/11
to rav...@googlegroups.com
The problem is that you can't load entities implementing IDynamicMetaObject from the client.
When you are doing that, it assumes that you want a dynamic instance, and gives you that.

Ayende Rahien

unread,
Feb 10, 2011, 5:08:25 AM2/10/11
to rav...@googlegroups.com
The reason for that, FWIW, is that we don't have a good way to deserialize a dynamic entity

jim

unread,
Feb 10, 2011, 5:44:28 AM2/10/11
to ravendb
Please check out my test code.

I used earlier version "RavenDB-Build-147", the code works fine.

On Feb 10, 6:08 pm, Ayende Rahien <aye...@ayende.com> wrote:
> The reason for that, FWIW, is that we don't have a good way to deserialize a
> dynamic entity
>
> On Thu, Feb 10, 2011 at 12:08 PM, Ayende Rahien <aye...@ayende.com> wrote:
> > The problem is that you can't load entities implementing IDynamicMetaObject
> > from the client.
> > When you are doing that, it assumes that you want a dynamic instance, and
> > gives you that.
>

Ayende Rahien

unread,
Feb 10, 2011, 8:37:29 AM2/10/11
to rav...@googlegroups.com
Fixed

jim

unread,
Feb 10, 2011, 7:56:28 PM2/10/11
to ravendb
Where can I get the fixed code?

On Feb 10, 9:37 pm, Ayende Rahien <aye...@ayende.com> wrote:
> Fixed
>

jim

unread,
Feb 11, 2011, 1:26:12 AM2/11/11
to ravendb
HI

I update to "RavenDB-Unstable-Build-274", the exception was gone, but
throw a new exception:

Test method
Kooboo.CMS.Content.Persistence.RavenDB.Embedded.Tests.InsertUpdateDeleteTests.Export_Schema_Data
threw exception:
System.InvalidCastException: Unable to cast object of type
'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.

Raven.Database.Json.JsonDynamicConverter.ReadJson(JsonReader reader,
Type objectType, Object existingValue, JsonSerializer serializer) in c:
\Builds\raven-unstable\Raven.Abstractions\Json
\JsonDynamicConverter.cs: line 55
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IWrappedDictionary
dictionary, JsonReader reader, JsonDictionaryContract contract, String
id) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json
\Serialization\JsonSerializerInternalReader.cs: line 634
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateDictionary(JsonReader
reader, JsonDictionaryContract contract, String id) in d:\Development
\Releases\Json\Working\Src\Newtonsoft.Json\Serialization
\JsonSerializerInternalReader.cs: line 593
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader
reader, Type objectType, JsonContract contract, JsonProperty member,
Object existingValue) in d:\Development\Releases\Json\Working\Src
\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs: line
387
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader
reader, Type objectType, JsonContract contract, JsonProperty member,
Object existingValue) in d:\Development\Releases\Json\Working\Src
\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs: line
223
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader
reader, Type objectType, JsonContract contract) in d:\Development
\Releases\Json\Working\Src\Newtonsoft.Json\Serialization
\JsonSerializerInternalReader.cs: line 208
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader
reader, Type objectType) in d:\Development\Releases\Json\Working\Src
\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs: line
118
Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,
Type objectType) in d:\Development\Releases\Json\Working\Src
\Newtonsoft.Json\JsonSerializer.cs: line 418
Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type
objectType) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json
\JsonSerializer.cs: line 413
Raven.Client.Client.JsonExtensions.Deserialize(JObject self, Type
type, DocumentConvention convention) in c:\Builds\raven-unstable
\Raven.Client.Lightweight\Client\JsonExtensions.cs: line 30
Raven.Client.Document.InMemoryDocumentSessionOperations.ConvertToEntity[T]
(String id, JObject documentFound, JObject metadata) in c:\Builds
\raven-unstable\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs: line 391
Raven.Client.Document.InMemoryDocumentSessionOperations.TrackEntity[T]
(String key, JObject document, JObject metadata) in c:\Builds\raven-
unstable\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs: line 318
Raven.Client.Document.AbstractDocumentQuery`2.Deserialize(JObject
result) in c:\Builds\raven-unstable\Raven.Client.Lightweight\Document
\AbstractDocumentQuery.cs: line 1256
System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
Raven.Client.Document.AbstractDocumentQuery`2.GetEnumerator() in c:
\Builds\raven-unstable\Raven.Client.Lightweight\Document
\AbstractDocumentQuery.cs: line 440
System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
Kooboo.CMS.Content.Persistence.RavenDB.Embedded.Tests.InsertUpdateDeleteTests.Export_Schema_Data()
in E:\Projects\Kooboo\src\trunk\Kooboo.CMS\Kooboo.CMS.Content
\Kooboo.CMS.Content.Persistence.RavenDB.Embedded.Tests
\InsertUpdateDeleteTests.cs: line 106


jim

unread,
Feb 11, 2011, 8:19:52 PM2/11/11
to ravendb
Any news?

Ayende Rahien

unread,
Feb 13, 2011, 10:47:56 AM2/13/11
to rav...@googlegroups.com
Can you show me code that reproduces this?

On Sat, Feb 12, 2011 at 3:19 AM, jim <hjf...@gmail.com> wrote:
Any news?

jim

unread,
Feb 15, 2011, 10:14:56 PM2/15/11
to ravendb
hi,

The code I sent you before. I only update the ravendb to the "RavenDB-
Unstable-Build-274".

I will send you again, it was updated to "RavenDB-Unstable-Build-274"
already.

On Feb 13, 11:47 pm, Ayende Rahien <aye...@ayende.com> wrote:
> Can you show me code that reproduces this?
>
> On Sat, Feb 12, 2011 at 3:19 AM, jim <hjf1...@gmail.com> wrote:
> > Any news?

Ayende Rahien

unread,
Feb 16, 2011, 4:33:39 AM2/16/11
to rav...@googlegroups.com
You have old dlls in the bin directory.
Once I removed all the dlls to the latest build, the test worked

jim

unread,
Feb 16, 2011, 6:40:15 AM2/16/11
to ravendb
Very strange.
If I only check and run the test "Export_Schema_Data", it works fine.
But if I run all the tests, the test "Export_Schema_Data" will throw
the exception. Please have a try.


On Feb 16, 5:33 pm, Ayende Rahien <aye...@ayende.com> wrote:
> You have old dlls in the bin directory.
> Once I removed all the dlls to the latest build, the test worked
>

Ayende Rahien

unread,
Feb 16, 2011, 8:08:50 AM2/16/11
to rav...@googlegroups.com
Thanks ,fixed

jim

unread,
Feb 16, 2011, 8:38:03 PM2/16/11
to ravendb
So bad, update to RavenDB-Unstable-Build-280, but the issue still
exists.

I am waiting so long for this issue.

On Feb 16, 9:08 pm, Ayende Rahien <aye...@ayende.com> wrote:
> Thanks ,fixed
>

Ayende Rahien

unread,
Feb 17, 2011, 7:59:56 AM2/17/11
to rav...@googlegroups.com
What is the exact stack trace?
I verified that you scenario worked

jim

unread,
Feb 17, 2011, 8:23:19 PM2/17/11
to ravendb
HI

I download the lastest version "RavenDB-Unstable-Build-283", the issue
was gone. But I retry "RavenDB-Unstable-Build-280" again, I am sure
the issue was still exists in that version.

On Feb 17, 8:59 pm, Ayende Rahien <aye...@ayende.com> wrote:
> What is the exact stack trace?
> I verified that you scenario worked
>

Sean Pataky

unread,
Jan 21, 2014, 2:17:30 PM1/21/14
to rav...@googlegroups.com
I was getting this error after a Query with Includes.  I tried to Load the related documents and that's where I received the cast exception.
 
I traced it to Raven client assemblies DocumentSessions.cs in
 
public T Load<T>(string id)
 
I changed:
return (T)existingEntity;
to
return JsonConvert.DeserializeObject<T>(existingEntity.ToString());
and recompiled ravendb assemblies.
 
Using that I do not receive the invalid cast exception 
 
 
 
 
 
 

 

 

 

(T)existingEntit

 
 

Oren Eini (Ayende Rahien)

unread,
Jan 22, 2014, 1:37:28 AM1/22/14
to ravendb
You are replying to a thread from 2011.
Please create a new thread, with full details. Including a failing test.

Join us in the RavenDB Conference: 7 - 11 April, 2014

Oren Eini
CEO
Hibernating Rhinos
Office:    +972-4-674-7811
Fax:       +972-153-4622-7811





--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages