diff --git a/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs b/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs index e3322d483d..8492aaef6a 100644 --- a/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs +++ b/src/umbraco.editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs @@ -334,34 +334,24 @@ namespace umbraco.editorControls.tinyMCE3.webcontrol } else { - var widthProperty = imageMedia.Properties.FirstOrDefault(x => x.Alias == "umbracoWidth"); - var heightProperty = imageMedia.Properties.FirstOrDefault(x => x.Alias == "umbracoHeight"); - var umbracoFileProperty = imageMedia.Properties.FirstOrDefault(x => x.Alias == "umbracoFile"); + // We're doing .Any checks here instead of FirstOrDefault because the default value of Properties + // is not null but default(KeyedCollection). This is a bit easier to read. + // To clarify: imageMedia.Properties.FirstOrDefault(x => x.Alias == "umbracoWidth") == null; will NOT work. var widthValue = string.Empty; - try - { - widthValue = widthProperty.Value.ToString(); - } - catch (Exception wx) - { - // For some reason widthProperty == null returns false when the widthproperty is actually null... - } + if (imageMedia.Properties.Any(x => x.Alias == "umbracoWidth")) + widthValue = imageMedia.Properties.First(x => x.Alias == "umbracoWidth").Value.ToString(); var heightValue = string.Empty; - try - { - heightValue = heightProperty.Value.ToString(); - } - catch (Exception ex) - { - // For some reason heightProperty == null returns false when the heightProperty is actually null... - } - - + if (imageMedia.Properties.Any(x => x.Alias == "umbracoHeight")) + heightValue = imageMedia.Properties.First(x => x.Alias == "umbracoHeight").Value.ToString(); + // Format the tag - if (umbracoFileProperty != null) + if (imageMedia.Properties.Any(x => x.Alias == "umbracoFile")) + { + var umbracoFileProperty = imageMedia.Properties.First(x => x.Alias == "umbracoFile"); tempTag = string.Format("{0} rel=\"{1},{2}\" src=\"{3}\" />", tempTag, widthValue, heightValue, umbracoFileProperty.Value); + } } html = html.Replace(tag.Value, tempTag);