U4-2523 - GetValue throws InvalidCastException for True/False datatype

Created by Tom Fulton 18 Jul 2013, 16:54:58 Updated by Morten Christensen 12 Aug 2013, 14:26:19

Relates to: U4-2397

I'm using the built-in True/False datatype to mark a node as Featured. When I attempt to use .GetValue, I get an InvalidCastException, whether the value is empty (0) or checked (1)

var contentService = ApplicationContext.Services.ContentService; var content = contentService.GetById(3423); var val1 = content.GetValue("isFeatured"); // returns 0 (integer) var val2 = content.GetValue("isFeatured"); // throws System.InvalidCastException: Specified cast is not valid. Umbraco.Core.Models.ContentBase.GetValue(String propertyTypeAlias) +47

When using PublishedContent, both calls return False as expected:

var publishedContent = Umbraco.TypedContent(3423); var pval1 = publishedContent.GetPropertyValue("isFeatured"); // returns False var pval2 = publishedContent.GetPropertyValue("isFeatured"); // returns False

Comments

Tom Fulton 18 Jul 2013, 17:02:59

FYI, there's a somewhat similar issue where .GetValue throws an InvalidCastException when the value is null. I can gather more details on that if needed.


Morten Christensen 12 Aug 2013, 14:26:13

This should be fixed in commit 86811fe5075ec3d5ce0d2e0bc97260857c19a252 and somewhat related to U4-2397. Part of the fix was making the GetValue a bit more robust, so that it can convert True/False (stored as 1/0) to boolean.


Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Easy

Category: Architecture

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.2

Due in version: 6.1.4

Sprint:

Story Points:

Cycle: