|
1 | | -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.ComponentModel.DataAnnotations; |
3 | 4 | using System.Linq; |
4 | 5 | using System.Text.RegularExpressions; |
@@ -160,15 +161,26 @@ public override string ConvertDbToString(Property property, PropertyType propert |
160 | 161 | } |
161 | 162 | else |
162 | 163 | { |
163 | | - // Create a fake property using the property abd stored value |
164 | | - var prop = new Property(propType, propValues[propKey] == null ? null : propValues[propKey].ToString()); |
| 164 | + try |
| 165 | + { |
| 166 | + // Create a fake property using the property abd stored value |
| 167 | + var prop = new Property(propType, propValues[propKey] == null ? null : propValues[propKey].ToString()); |
165 | 168 |
|
166 | | - // Lookup the property editor |
167 | | - var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias); |
| 169 | + // Lookup the property editor |
| 170 | + var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias); |
168 | 171 |
|
169 | | - // Get the editor to do it's conversion, and store it back |
170 | | - propValues[propKey] = propEditor.ValueEditor.ConvertDbToString(prop, propType, |
171 | | - ApplicationContext.Current.Services.DataTypeService); |
| 172 | + // Get the editor to do it's conversion, and store it back |
| 173 | + propValues[propKey] = propEditor.ValueEditor.ConvertDbToString(prop, propType, |
| 174 | + ApplicationContext.Current.Services.DataTypeService); |
| 175 | + } |
| 176 | + catch (InvalidOperationException) |
| 177 | + { |
| 178 | + // https://github.com/umco/umbraco-nested-content/issues/111 |
| 179 | + // Catch any invalid cast operations as likely means courier failed due to missing |
| 180 | + // or trashed item so couldn't convert a guid back to an int |
| 181 | + |
| 182 | + propValues[propKey] = null; |
| 183 | + } |
172 | 184 | } |
173 | 185 |
|
174 | 186 | } |
@@ -225,18 +237,29 @@ public override object ConvertDbToEditor(Property property, PropertyType propert |
225 | 237 | } |
226 | 238 | else |
227 | 239 | { |
228 | | - // Create a fake property using the property abd stored value |
229 | | - var prop = new Property(propType, propValues[propKey] == null ? null : propValues[propKey].ToString()); |
| 240 | + try |
| 241 | + { |
| 242 | + // Create a fake property using the property abd stored value |
| 243 | + var prop = new Property(propType, propValues[propKey] == null ? null : propValues[propKey].ToString()); |
230 | 244 |
|
231 | | - // Lookup the property editor |
232 | | - var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias); |
| 245 | + // Lookup the property editor |
| 246 | + var propEditor = PropertyEditorResolver.Current.GetByAlias(propType.PropertyEditorAlias); |
233 | 247 |
|
234 | | - // Get the editor to do it's conversion |
235 | | - var newValue = propEditor.ValueEditor.ConvertDbToEditor(prop, propType, |
236 | | - ApplicationContext.Current.Services.DataTypeService); |
| 248 | + // Get the editor to do it's conversion |
| 249 | + var newValue = propEditor.ValueEditor.ConvertDbToEditor(prop, propType, |
| 250 | + ApplicationContext.Current.Services.DataTypeService); |
237 | 251 |
|
238 | | - // Store the value back |
239 | | - propValues[propKey] = (newValue == null) ? null : JToken.FromObject(newValue); |
| 252 | + // Store the value back |
| 253 | + propValues[propKey] = (newValue == null) ? null : JToken.FromObject(newValue); |
| 254 | + } |
| 255 | + catch (InvalidOperationException) |
| 256 | + { |
| 257 | + // https://github.com/umco/umbraco-nested-content/issues/111 |
| 258 | + // Catch any invalid cast operations as likely means courier failed due to missing |
| 259 | + // or trashed item so couldn't convert a guid back to an int |
| 260 | + |
| 261 | + propValues[propKey] = null; |
| 262 | + } |
240 | 263 | } |
241 | 264 |
|
242 | 265 | } |
|
0 commit comments