U4-2732 - Creating Media Items gives 'Error uploading to parent' message

Created by Peter Rombouts 28 Aug 2013, 07:46:04 Updated by Dallas Taylor 22 Jan 2015, 20:13:15

Duplicates: U4-2711

When trying to create/upload a new media item into Umbraco, the following error appears:

ERROR umbraco.presentation.umbraco.webservices.MediaUploader - [Thread 50] Error uploading to parent -1 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.Services.PackagingService.Export(IContentBase contentBase, String nodeName) at Umbraco.Core.Services.PackagingService.Export(IMedia media, Boolean deep) 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)

This happened after updating from 6.1.3 to 6.1.4.

  • The original codebase was 4.7-ish

The code breaks in the file umbraco.editorControls\imagecropper\DataTypeData.cs

I have fixed this using the following extra nullcheck above the 'Value.ToString() line: using System.Xml;

namespace umbraco.editorControls.imagecropper { public class DataTypeData : umbraco.cms.businesslogic.datatype.DefaultData { public DataTypeData(umbraco.cms.businesslogic.datatype.BaseDataType DataType) : base(DataType)

    public override XmlNode ToXMl(XmlDocument data)
    {
        // Added extra null check on Value
        if (Value != null &&
            Value.ToString() != "") {
            XmlDocument xd = new XmlDocument();
            xd.LoadXml(Value.ToString());
            return data.ImportNode(xd.DocumentElement, true);
        } else {
            return base.ToXMl(data);
        }

    }
}

}

I cannot reproduce the bug on all our Umbraco 6.1.4 based sites, but this fix works for one specific customer.

Extra information; There are many Media items, and we use ImageCropper. By removing ImageCropper, the problem did not go away.

Comments

Arjan Hoogervorst 28 Aug 2013, 14:40:45

I had the same issue after upgrading to 6.1.4. Applying this fix worked like a charm for me!


Robert Stocks 28 Aug 2013, 14:42:41

Duplicate: U4-2711


Martin Griffiths 24 Oct 2014, 14:17:45

We are getting this in our logs too. Does it cause any problems in the backoffice? None of our users have raised it as a problem so far.

The error we are getting is slightly different as below

2014-10-24 16:25:58,502 [70] ERROR umbraco.presentation.umbraco.webservices.MediaUploader [(null)] - [Thread 70] Error uploading to parent 8312

System.Xml.XmlException: Root element is missing. at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at lcpcorporate.Library.MediaEventHandler.Media_AfterSave(Media sender, EventArgs e) at umbraco.cms.businesslogic.media.Media.SaveEventHandler.Invoke(Media sender, SaveEventArgs e) at umbraco.cms.businesslogic.media.Media.Save() at umbraco.cms.businesslogic.media.UmbracoFileMediaFactory.DoHandleMedia(Media media, PostedMediaFile uploadedFile, User user) at umbraco.cms.businesslogic.media.UmbracoMediaFactory.HandleMedia(Int32 parentNodeId, PostedMediaFile postedFile, User user) at umbraco.presentation.umbraco.webservices.MediaUploader.ProcessUploadRequest(HttpContext context)


Dallas Taylor 22 Jan 2015, 20:13:15

We were getting a similar error and the cause ended up being that the Folder Media Type had lost its Allowed Child nodetypes settings (on the structure tab). None of the Media Types were selected. The default is for File, Folder and Image to be checked. This was on v6.1.6

We found that when uploading an image to a folder that there was no error and it looked to work but the image would not be added. The Umbraco log file contained this error message and stack trace:

{{2015-01-22 13:56:59,477 [7] ERROR umbraco.presentation.umbraco.webservices.MediaUploader - [Thread 26] Error uploading to parent 9604

System.NullReferenceException: Object reference not set to an instance of an object. at umbraco.presentation.umbraco.webservices.MediaUploader.ProcessUploadRequest(HttpContext context)}}

The solution was to check the Folder, Image and File Media Types on the Folder Media Type structure tab. This has occurred multiple times on this site so we have a strange issue where the Media Type settings are getting lost.


Priority: Normal

Type: Bug

State: Duplicate

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.1.4, 6.1.6

Due in version:

Sprint:

Story Points:

Cycle: