U4-2711 - DAMP throws unknown exception on image upload with image cropper

Created by Colin Bailey 23 Aug 2013, 14:10:40 Updated by Sebastiaan Janssen 31 Aug 2013, 09:26:24

Is duplicated by: U4-2732

After creating a custom image type with an image cropper property. DAMP throws an 'unknown exception' when attempting to upload an image of this type. Please note the error message seems to vary from time to time

Versions: Umbraco 6.1.4 Digibiz Advanced Media Picker 2.5

Steps taken: Create a new media type underneath image call it 'Custom image' for example Allow 'Custom image' as a child node type of Folder. Create a custom datatype using Image cropper as the editor. Use umbracoFile as the property alias, check save crop images and add a custom crop. Add this custom image cropper as a property of 'Custom image'. Create a custom image picker using DAMP, in the settings allow it to select and create 'Custom image'. Assign the custom image picker to a document type. In the content menu try and upload an image of type 'Custom image'.

Error Message from log: 2013-08-23 15:05:53,914 [71] INFO umbraco.BusinessLogic.Log - [Thread 43] Redirected log call (please use Umbraco.Core.Logging.LogHelper instead of umbraco.BusinessLogic.Log) | Type: Error | User: 0 | NodeId: -1 | Comment: Exception: Object reference not set to an instance of an object. - StackTrace: at DigibizAdvancedMediaPicker.DigibizAdvancedMediaPicker.ConvertXML(XDocument xmlDocument) 2013-08-23 15:06:06,720 [71] INFO umbraco.BusinessLogic.Log - [Thread 24] Redirected log call (please use Umbraco.Core.Logging.LogHelper instead of umbraco.BusinessLogic.Log) | Type: Error | User: 0 | NodeId: -1 | Comment: Exception: Object reference not set to an instance of an object. - StackTrace: at umbraco.editorControls.imagecropper.DataTypeData.ToXMl(XmlDocument data) at Umbraco.Core.Models.PropertyExtensions.ToXml(Property property, IDataTypeService dataTypeService) at Umbraco.Core.Models.PropertyExtensions.ToXml(Property property) at Umbraco.Core.Services.PackagingService.Export(IContentBase contentBase, String nodeName) at Umbraco.Core.Services.PackagingService.Export(IMedia media, Boolean deep) at Umbraco.Core.Models.ContentExtensions.ToXml(IMedia media) at Umbraco.Core.Services.MediaService.CreateMediaWithIdentity(String name, Int32 parentId, String mediaTypeAlias, Int32 userId) at umbraco.cms.businesslogic.media.Media.MakeNew(String Name, MediaType dct, User u, Int32 ParentId) at DigibizAdvancedMediaPicker.CreateMediaItem.BtnCreate_Click(Object sender, EventArgs e) 2013-08-23 15:06:08,633 [71] ERROR umbraco.DataLayer.SqlHelper1[[System.Data.SqlClient.SqlParameter, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] - [Thread 34] Error executing query select xml from cmsContentXml where nodeID = 1069 System.ArgumentException: The query didn't return a value. at umbraco.DataLayer.SqlHelper1.ExecuteXmlReader(String commandText, P[] parameters) at umbraco.DataLayer.SqlHelper`1.ExecuteXmlReader(String commandText, IParameter[] parameters)

1 Attachments

Download patch.diff

Comments

Sebastiaan Janssen 23 Aug 2013, 17:34:24

Please report plugin issues at their forums http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker/digibiz-advanced-media-picker


Robert Stocks 27 Aug 2013, 14:49:27

I am not sure that this is a plugin issue - umbraco.editorControls.imagecropper.DataTypeData.ToXMl(XmlDocument data) is the method that is generating the error.

I think that the ToXMl method of the image cropper data Type should add a NULL check to it's use of the "Value" field.

I have attached a patch to fix this but could do a pull request instead if required.


Chris Mahoney 27 Aug 2013, 21:07:58

I'm also getting an "object reference not set to an instance of an object" error in that same .ToXMl method, and I don't have DAMP. This issue has only started happening since upgrading to 6.1.4.


Sebastiaan Janssen 28 Aug 2013, 07:41:50

Thanks @Robert the patch only treats the symptom and not the underlying issue. Something else must've changed to make the Value be null. I see Shannon made some changes to umbraco.cms.businesslogic.datatype.DefaultData for 6.1.4 so I'm hoping he might know what could be causing this. Do any of you use a load balancing setup by any chance?


Colin Bailey 28 Aug 2013, 08:50:45

@Thanks for your feedback guys.. in particular the patch @Robert. Not sure how to apply this to an otherwise fully functional and populated site without compromising the work done so far.

I've recently completed two sites using this setup with 6.1.3 without issue. None of these sites, including 6.1.4, are in a load balanced environment. Looking forward to an update.


Shannon Deminick 28 Aug 2013, 08:54:32

@Chris, can you please post a stack trace and give us a way to replicate this without DAMP please?


Robert Stocks 28 Aug 2013, 09:17:18

@Sebastiaan, all the other overides of toXMl in other editor controls include an is null check on value

for examples see src\umbraco.editorControls\CsvToXmlData.cs - LINE 81 src\umbraco.editorControls\datepicker\DateData.cs - LINE 14

additionally the base implementation of toXMl also includes an is null check. src\umbraco.cms\businesslogic\datatype\DefaultData.cs - LIVE 137

This issue is specific to the image cropper datatype, and I think my patch is the correct solution, but I am very interesting in learning from you guys - please let me know what I have missed (in a different channel to avoid cluttering the issue tracker if you like)


Sebastiaan Janssen 28 Aug 2013, 09:27:35

@Robert that's what the issue tracker is for! :-) So, sure, maybe I'm missing something. It shouldn't suddenly start throwing null exceptions where it never did that before, which is why I think it's a different issue. I do agree that there NEEDS to be a null check there but I just want to figure out why it now is suddenly null, there may be a larger issue.

So, I tried:

  • Configure Image Cropper datatype to have at least 1 crop.
  • Added it to the built in Image media type on a new tab
  • Right-click, create new Image
  • Use the upload field to upload an image
  • Save the image (twice, else the cropper won't show anything)
  • Use the cropper to create a crop
  • Save again

No errors.

What did I miss?


Robert Stocks 28 Aug 2013, 10:34:23

@Sebastiaan, The problem stems from Umbraco.Core.Services.MediaService.CreateMediaWithIdentity

if you change step 3 of your walk through to use the upload button from the tool bar to upload an image you will trigger this.

2013-08-28 11:26:46,570 [47] ERROR umbraco.presentation.umbraco.webservices.MediaUploader - [Thread 14] Error uploading to parent 1055 System.NullReferenceException: Object reference not set to an instance of an object. at umbraco.editorControls.imagecropper.DataTypeData.ToXMl(XmlDocument data) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\umbraco.editorControls\imagecropper\DataTypeData.cs:line 12 at Umbraco.Core.Models.PropertyExtensions.ToXml(Property property, IDataTypeService dataTypeService) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\Umbraco.Core\Models\PropertyExtensions.cs:line 56 at Umbraco.Core.Models.PropertyExtensions.ToXml(Property property) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\Umbraco.Core\Models\PropertyExtensions.cs:line 25 at Umbraco.Core.Services.PackagingService.Export(IContentBase contentBase, String nodeName) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\Umbraco.Core\Services\PackagingService.cs:line 150 at Umbraco.Core.Services.PackagingService.Export(IMedia media, Boolean deep) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\Umbraco.Core\Services\PackagingService.cs:line 818 at Umbraco.Core.Models.ContentExtensions.ToXml(IMedia media) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\Umbraco.Core\Models\ContentExtensions.cs:line 613 at Umbraco.Core.Services.MediaService.CreateMediaWithIdentity(String name, Int32 parentId, String mediaTypeAlias, Int32 userId) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\Umbraco.Core\Services\MediaService.cs:line 139 at umbraco.cms.businesslogic.media.Media.MakeNew(String Name, MediaType dct, User u, Int32 ParentId) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\umbraco.cms\businesslogic\media\Media.cs:line 95 at umbraco.cms.businesslogic.media.UmbracoMediaFactory.HandleMedia(Int32 parentNodeId, PostedMediaFile postedFile, User user) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\umbraco.cms\businesslogic\media\UmbracoMediaFactory.cs:line 55 at umbraco.presentation.umbraco.webservices.MediaUploader.ProcessUploadRequest(HttpContext context) in c:\Users\roberts\Documents\GitHub\Umbraco-CMS\src\Umbraco.Web\umbraco.presentation\umbraco\webservices\MediaUploader.ashx.cs:line 183

I note that in this situation the site fails to upload the image (the media item gets created without an image)


Manuel Baumann 28 Aug 2013, 13:04:35

I had the same issue here:

2013-08-28 14:47:52,213 [35] ERROR umbraco.presentation.umbraco.webservices.MediaUploader - [Thread 79] Error uploading to parent 1097 System.NullReferenceException: Object reference not set to an instance of an object. at umbraco.editorControls.imagecropper.DataTypeData.ToXMl(XmlDocument data) at Umbraco.Core.Models.PropertyExtensions.ToXml(Property property, IDataTypeService dataTypeService) at Umbraco.Core.Models.PropertyExtensions.ToXml(Property property) at Umbraco.Core.Services.PackagingService.Export(IContentBase contentBase, String nodeName) at Umbraco.Core.Services.PackagingService.Export(IMedia media, Boolean deep) at Umbraco.Core.Models.ContentExtensions.ToXml(IMedia media) at Umbraco.Core.Services.MediaService.CreateMediaWithIdentity(String name, Int32 parentId, String mediaTypeAlias, Int32 userId) at umbraco.cms.businesslogic.media.Media.MakeNew(String Name, MediaType dct, User u, Int32 ParentId) at umbraco.cms.businesslogic.media.UmbracoMediaFactory.HandleMedia(Int32 parentNodeId, PostedMediaFile postedFile, User user) at umbraco.presentation.umbraco.webservices.MediaUploader.ProcessUploadRequest(HttpContext context)


Arjan Hoogervorst 28 Aug 2013, 14:08:37

I'm getting the same error when uploading images, when the Media Type "Image" has an "Image Cropper" property, as described by both Robert and Manual. This problem started after upgrading to version 6.1.4.


Robert Stocks 28 Aug 2013, 14:34:37

I have created a pull request with a fix for this: https://github.com/umbraco/Umbraco-CMS/pull/119


Arjan Hoogervorst 28 Aug 2013, 14:36:01

I've applied the fix Robert suggests to my 6.1.4 installation, and it works like a charm!


Manuel Baumann 28 Aug 2013, 14:37:38

have a look at this issue U4-2732 (http://issues.umbraco.org/issue/U4-2732). This solve this issue.


Chris Mahoney 28 Aug 2013, 20:19:08

@Shannon This probably isn't so important now that two other people posted traces, but mine's slightly different.

[NullReferenceException: Object reference not set to an instance of an object.] umbraco.editorControls.imagecropper.DataTypeData.ToXMl(XmlDocument data) +31 Umbraco.Core.Models.PropertyExtensions.ToXml(Property property, IDataTypeService dataTypeService) +533 Umbraco.Core.Services.PackagingService.Export(IContentBase contentBase, String nodeName) +1517 Umbraco.Core.Services.PackagingService.Export(IMedia media, Boolean deep) +238 Umbraco.Core.Services.MediaService.CreateMediaWithIdentity(String name, Int32 parentId, String mediaTypeAlias, Int32 userId) +404 umbraco.mediaTasks.Save() +187 umbraco.presentation.create.dialogHandler_temp.Create(String NodeType, Int32 TypeId, Int32 NodeId, String Text) +754 umbraco.cms.presentation.create.controls.media.sbmt_Click(Object sender, EventArgs e) +224 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +153 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3706

The actual steps to get that:

Add an Image Cropper to the Image media type.

Go to the Media section and right-click > Create.

Give it a name and make it an Image.

I then get a YSOD with the exception, before actually uploading the image file.

The media item itself is still created, so I can Reload Nodes and then upload the file.


Shannon Deminick 29 Aug 2013, 02:22:10

Ok, looks like I can replicate. Easiest way is to just add a cropper to the media image type and then try to create an image and you'll get a YSOD. Will fix.


Shannon Deminick 29 Aug 2013, 02:28:16

Fixed in 357dc6ec8e9c481c801d22acb957f0ce9c759c2c, a couple null checks required so this doesn't accidentally happen to other implementations of IData with a null value.


Priority: Normal

Type: Bug

State: Fixed

Assignee: Shannon Deminick

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.4

Due in version: 6.1.5

Sprint:

Story Points:

Cycle: