U4-2822 - Datepicker throws "Specified cast is not valid" when saving through API

Created by Bo Kingo Damgaard 10 Sep 2013, 08:58:58 Updated by Sebastiaan Janssen 30 Sep 2013, 13:16:46

I'm unable to store a date in a datepicker using the API, because Umbraco throws "Specified cast is not valid" even though the date is valid. This is an issues both when using the old and new API, but only since 6.1.4. It worked in 6.1.3, and it might be related to this issue http://issues.umbraco.org/issue/U4-2523

Code to reproduce: Install a simple website, and add a datepicker (alias date) to umbTextpage doctype. Then run this code somehow

ContentType DocType = (ContentType) ApplicationContext.Current.Services.ContentTypeService.GetContentType("umbTextpage"); var parent = ApplicationContext.Current.Services.ContentService.GetById(1051); Content NewDocument = new Content("test",parent,DocType); // Only use one of these lines. Either one will produce the same result when saving NewDocument.SetValue("date", "2013-03-09"); NewDocument.Properties["date"].Value = "2013-03-09"; ApplicationContext.Current.Services.ContentService.SaveAndPublish(NewDocument);

1 Attachments

Download U4-2822.zip


Sebastiaan Janssen 10 Sep 2013, 10:56:40

Now try this and note that you don't need to get the full doctype, just provide the alias

var cs = ApplicationContext.Current.Services.ContentService; var content = cs.CreateContent("Test", 1120, "umbTextPage"); content.SetValue("date", new DateTime(2013, 03, 09)); cs.Save(content);

I'm not sure what changed here though, it actually saves the date correctly even though it's throwing an exception now.

Bo Kingo Damgaard 10 Sep 2013, 11:25:02

Oh yes, I forgot to mention that. It saves the data but throws an error

John Walker 13 Sep 2013, 09:21:25

This seems to also be an issue when you package up content which has a datepicker property when you attempt to install the package the exception below is thrown. As you said this does not stop the content being created but it does stop any of the package actions running after.

[InvalidCastException: Specified cast is not valid.] umbraco.editorControls.datepicker.DateData.ToXMl(XmlDocument d) +87 Umbraco.Core.Models.PropertyExtensions.ToXml(Property property, IDataTypeService dataTypeService) +356 Umbraco.Core.Models.PropertyExtensions.ToXml(Property property) +38 Umbraco.Core.Services.PackagingService.Export(IContentBase contentBase, String nodeName) +1271 Umbraco.Core.Services.PackagingService.Export(IContent content, Boolean deep) +119 Umbraco.Core.Models.ContentExtensions.ToXml(IContent content) +42 Umbraco.Web.Search.ExamineEvents.IndexConent(IContent sender) +22 Umbraco.Core.EnumerableExtensions.ForEach(IEnumerable1 items, Action1 action) +141 Umbraco.Web.Search.ExamineEvents.ContentServiceSaved(IContentService sender, SaveEventArgs1 e) +55 Umbraco.Core.Events.TypedEventHandler2.Invoke(TSender sender, TEventArgs e) +0 Umbraco.Core.Events.EventExtensions.RaiseEvent(TypedEventHandler2 eventHandler, TArgs args, TSender sender) +16 Umbraco.Core.Services.ContentService.Save(IEnumerable1 contents, Int32 userId, Boolean raiseEvents) +673 Umbraco.Core.Services.PackagingService.ImportContent(XElement element, Int32 parentId, Int32 userId) +198 umbraco.cms.businesslogic.packager.Installer.InstallBusinessLogic(Int32 packageId, String tempDir) +2289 umbraco.presentation.developer.packages.Installer.ProcessInstall(String currentStep) +208 umbraco.presentation.developer.packages.Installer.Page_Load(Object sender, EventArgs e) +425 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51 System.Web.UI.Control.OnLoad(EventArgs e) +92 umbraco.BasePages.BasePage.OnLoad(EventArgs e) +14 System.Web.UI.Control.LoadRecursive() +54 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

Sebastiaan Janssen 18 Sep 2013, 10:15:09

Fix is in revision dc1a67bfa2b97de2494d8a58d2691090d9394ef1

Attached is a custom build of 6.1.5 plus only the fix for this issue. Make sure to backup your bin folder and then copy the files in this zip file into your bin folder, overwriting the existing ones.

If there's any issues with this make sure to report here but it should all work fine with this patch in place.

Jon R. Humphrey 18 Sep 2013, 11:38:14

This is the error I'm receiving now:

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.ArteryFilter.Flush() +393 Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.ArteryFilter.Close() +15 System.IO.Stream.Dispose() +10 Umbraco.Web.UmbracoModule.DisposeHttpContextItems(HttpContext http) +153 Umbraco.Web.UmbracoModule.b__9(Object sender, EventArgs args) +305 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

Sebastiaan Janssen 18 Sep 2013, 11:40:00

Make sure to turn off Browser Link in VS2013.. Sorry, it breaks Umbraco. :(

Jon R. Humphrey 18 Sep 2013, 11:45:52

That was it Sebastiaan! Also, install of Standard Website MVC starter package was published, even with the error above so I think we're good! However, with BrowserLink on by default, how should I verify this for you all without starting all over again? Jon

Sebastiaan Janssen 18 Sep 2013, 11:48:01

I'm not sure what you mean? You can't use Browserlink with Umbraco 6.1.5 at the moment, we're looking to resolve this with Microsoft. We'll have a fix in place for 6.2.0, but for now you'll need to keep it turned off as advised on the 6.1.x download pages.

Jon R. Humphrey 18 Sep 2013, 11:52:22

Ahhh! As I installed via Nuget I didn't realise this! The download page mentions "You can disable Browser Link temporarily to get through the installer." does this mean I can turn it back on now that everything seems to be installed or would I have to turn it off and on every time I install something new into the site?

Sebastiaan Janssen 18 Sep 2013, 12:18:30

Nope, they broke Umbraco completely with VS2013RC. It has to stay off. I'll update the release notes when I get a chance.

Jon R. Humphrey 30 Sep 2013, 12:54:44

Sebastiaan, does this mean I can turn on my browserlink now if I update to v6.1.6?

Sebastiaan Janssen 30 Sep 2013, 12:56:19


Jon R. Humphrey 30 Sep 2013, 12:57:47

Thanks chief! #h5yr!

Sebastiaan Janssen 30 Sep 2013, 13:16:46

@Jon it's just been released: http://umbra.co/17iKnrN

Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.4, 6.1.5

Due in version: 6.1.6


Story Points: