Ex: Specified cast is not valid.

73 views
Skip to first unread message

Marcelo Volmaro

unread,
Jun 16, 2017, 9:29:16 PM6/16/17
to RavenDB - 2nd generation document database
In Raven4, I'm getting the exception: Specified cast is not valid.

   at Raven.Client.Json.BlittableJsonWriter.WriteMetadata()
   at Raven.Client.Json.BlittableJsonWriter.WriteStartObject()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, Object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Raven.Client.Documents.Session.EntityToBlittable.ConvertEntityToBlittable(Object entity, DocumentInfo documentInfo)
   at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData result)
   at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForSaveChanges()
   at Raven.Client.Documents.Session.Operations.BatchOperation.CreateRequest()
   at Raven.Client.Documents.Session.AsyncDocumentSession.<SaveChangesAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at DDS.Synchronizer.Server.Repository.Store.<SaveChangesAsync>d__13.MoveNext() in D:\Code\2DS\Aplicaciones\Synchronizer\DDS.Synchronizer.Server\Repository\Store_General.cs:line 59

This happens when I load an entity of type ApplicationVersion from the db (using a query/indexes) and then I try to save another ApplicationVersion into the db, in the same session.

Index:
internal sealed class ApplicationVersion_Indexes : AbstractIndexCreationTask<ApplicationVersion>
{
public ApplicationVersion_Indexes()
{
Map = versions => versions.Select(version => new
{
version.ApplicationId,
version.State,
Created_Ticks = version.Created.Ticks
});

Sort(x => x.Created.Ticks, SortOptions.Numeric);
}
}

Query:
await _session.Query<ApplicationVersionApplicationVersion_Indexes>().Where(x => x.ApplicationId == applicationId && x.State == VersionState.Valid)
.OrderByDescending(x => x.Created.Ticks)
.FirstOrDefaultAsync()



Grisha Kotler

unread,
Jun 17, 2017, 3:25:12 AM6/17/17
to rav...@googlegroups.com
Can you share a sample ApplicationVersion document?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oren Eini (Ayende Rahien)

unread,
Jun 17, 2017, 4:50:22 AM6/17/17
to ravendb
Better yet, a small test case would be wonderful

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 

Marcelo Volmaro

unread,
Jun 17, 2017, 8:32:51 AM6/17/17
to RavenDB - 2nd generation document database
public sealed class ApplicationVersion : IStorable
{
public ApplicationVersion()
{
Created = DateTime.UtcNow;
}

public string ApplicationId { get; set; }
public DateTime Created { get; set; }
public IEnumerable<File> Files { get; set; }
public IEnumerable<File> IncludedFiles { get; set; }
public Dictionary<string, string> Metadata { get; set; }
public VersionState State { get; set; }
public bool UpdateIncludedFiles { get; set; }

public string Id { get; set; }
}

public enum VersionState
{
MissingFiles,
Valid
}

Index:
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Marcelo Volmaro

unread,
Jun 18, 2017, 12:04:50 PM6/18/17
to RavenDB - 2nd generation document database
I can't reproduce this anymore since I restarted the server... I have a test project ready, but it seems that the issue is server related. 
If this happens again, I will also get a fiddler log...
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/d/optout.

--
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.

Marcelo Volmaro

unread,
Jun 19, 2017, 9:31:13 AM6/19/17
to RavenDB - 2nd generation document database
Ok.. I can reproduce it again, but it seems that there is some condition that I can't really get that's it's firing this... Is there any way I can help you debugging this?

Marcelo Volmaro

unread,
Jun 19, 2017, 9:50:41 AM6/19/17
to RavenDB - 2nd generation document database
And what's stranger is that even if I comment the only line where I'm actually saving an entity, the error still happens on a session with loaded entities and no one modified (but I'm calling SaveChangesAsync anyways).

Oren Eini (Ayende Rahien)

unread,
Jun 20, 2017, 1:47:50 PM6/20/17
to ravendb
What is the cast to / from?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Mon, Jun 19, 2017 at 4:50 PM, Marcelo Volmaro <mvol...@gmail.com> wrote:
And what's stranger is that even if I comment the only line where I'm actually saving an entity, the error still happens on a session with loaded entities and no one modified (but I'm calling SaveChangesAsync anyways).

--
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+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jun 20, 2017, 8:44:18 PM6/20/17
to RavenDB - 2nd generation document database
Raven.Client doesn't includes debug info, so I don't know. The exception doesn't has any additional information about that.
Do you have a symbol server that I can point out my VS?


On Tuesday, June 20, 2017 at 2:47:50 PM UTC-3, Oren Eini wrote:
What is the cast to / from?

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


On Mon, Jun 19, 2017 at 4:50 PM, Marcelo Volmaro <mvol...@gmail.com> wrote:
And what's stranger is that even if I comment the only line where I'm actually saving an entity, the error still happens on a session with loaded entities and no one modified (but I'm calling SaveChangesAsync anyways).

--
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.

Oren Eini (Ayende Rahien)

unread,
Jun 21, 2017, 12:53:52 AM6/21/17
to ravendb
What it it trying to cast to / from, I meant.
The full exception error, including all the details.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jun 21, 2017, 7:57:00 AM6/21/17
to RavenDB - 2nd generation document database
System.InvalidCastException occurred
  HResult=0x80004002
  Message=Specified cast is not valid.
  Source=Raven.Client
  StackTrace:
   at Raven.Client.Json.BlittableJsonWriter.WriteMetadata()
   at Raven.Client.Json.BlittableJsonWriter.WriteStartObject()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.WriteObjectStart(JsonWriter writer, Object value, JsonContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Raven.Client.Documents.Session.EntityToBlittable.ConvertEntityToBlittable(Object entity, DocumentInfo documentInfo)
   at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForEntitiesPuts(SaveChangesData result)
   at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.PrepareForSaveChanges()
   at Raven.Client.Documents.Session.Operations.BatchOperation.CreateRequest()
   at Raven.Client.Documents.Session.AsyncDocumentSession.<SaveChangesAsync>d__18.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)


This is the full error information. There is no additional information about what is being getting cast to what.

Oren Eini (Ayende Rahien)

unread,
Jun 21, 2017, 2:03:11 PM6/21/17
to ravendb
This is really strange, it is supposed to tell you from what to what the cast is.
Can you reproduce when this happens? It looks like something funky in the metadata.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811

 


--

Marcelo Volmaro

unread,
Jun 21, 2017, 2:32:48 PM6/21/17
to RavenDB - 2nd generation document database
I can reproduce locally 100% of the time... locally.

Here you have a test case that may/may not work. I'm also attaching the DB as you need data.

 
Please note that the first time you run the app (once the data is in the DB), it is possible that everything goes well, but please try to run it again a couple of times, as that's how I can reproduce this.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Jun 22, 2017, 9:31:24 AM6/22/17
to ravendb
Thanks, found it and we have a fix.

Thank you for the detailed bug report and the repro.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Marcelo Volmaro

unread,
Jun 22, 2017, 9:34:24 AM6/22/17
to RavenDB - 2nd generation document database
I want my "Bug reporter of the month" badge! :)

Oren Eini (Ayende Rahien)

unread,
Jun 26, 2017, 5:22:28 AM6/26/17
to ravendb
Send sup...@ravendb.net your snail mail details and your tshirt size, we'll send it to you
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+unsubscribe@googlegroups.com.

Oren Eini (Ayende Rahien)

unread,
Jun 26, 2017, 5:22:54 AM6/26/17
to ravendb
On a more serious note, we really appreciate you finding those issues and sending us a way to reproduce them locally.

Marcelo Volmaro

unread,
Jun 26, 2017, 9:07:21 AM6/26/17
to RavenDB - 2nd generation document database
NP... I really appreciate you for the hard work you and your team is doing to create one of the best DBs out of there...
Reply all
Reply to author
Forward
0 new messages