U4-1392 - Adding properties to custom media type gives error on media item

Created by Jeroen Breuer 05 Jan 2013, 16:07:47 Updated by Morten Christensen 09 Jan 2013, 12:49:40

The [DAMP 2.0 Samples|http://our.umbraco.org/FileDownload?id=3145] package adds custom media types with the following code: User adminUser = new User(0);

MediaType imageWide = CreateMediaType(adminUser, "ImageWide", "Crop - Wide sample", "wideImage", "Wide image");

///

/// Create a Media Type. /// /// /// /// /// /// /// private MediaType CreateMediaType(User adminUser, string mediaTypeName, string cropDataTypeName, string cropProperty, string cropName) { MediaType mediaType = MediaType.MakeNew(adminUser, mediaTypeName);

int imageTab = mediaType.AddVirtualTab("Image");
int cropTab = mediaType.AddVirtualTab("Crop");
int cropId = GetIdByName(cropDataTypeName);

mediaType.AddPropertyType(new DataTypeDefinition(UPLOAD_DATATYPE_ID), "umbracoFile", "Upload image");
mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoWidth", "Width");
mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoHeight", "Height");
mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoBytes", "Size");
mediaType.AddPropertyType(new DataTypeDefinition(LABEL_DATATYPE_ID), "umbracoExtension", "Type");
mediaType.AddPropertyType(new DataTypeDefinition(cropId), cropProperty, cropName);

mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoFile"), imageTab);
mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoWidth"), imageTab);
mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoHeight"), imageTab);
mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoBytes"), imageTab);
mediaType.SetTabOnPropertyType(mediaType.getPropertyType("umbracoExtension"), imageTab);
mediaType.SetTabOnPropertyType(mediaType.getPropertyType(cropProperty), cropTab);

mediaType.Text = mediaTypeName;
mediaType.IconUrl = "mediaPhoto.gif";
mediaType.Save();

return mediaType;

} After this I added another property to the custom media type through the backoffice. After this when I try to open a media item I get the following error. This error only happens to Media Types that are created with the above code.

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] Umbraco.Core.Persistence.Factories.PropertyFactory.BuildMediaEntity(IEnumerable`1 dtos) +334 Umbraco.Core.Persistence.Repositories.MediaRepository.GetPropertyCollection(Int32 id, Guid versionId, IMediaType contentType) +1199 Umbraco.Core.Persistence.Repositories.MediaRepository.GetByVersion(Guid versionId) +602 Umbraco.Core.Services.MediaService.GetByVersion(Guid versionId) +93 umbraco.cms.businesslogic.media.Media.setupNode() +180 umbraco.cms.businesslogic.CMSNode..ctor(Int32 Id) +36 umbraco.cms.presentation.editMedia.OnInit(EventArgs e) +104 System.Web.UI.Control.InitRecursive(Control namingContainer) +140 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +480

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

Comments

Morten Christensen 09 Jan 2013, 12:49:30

I can't recreate this 100% but I believe this issue is in part due to a caching issue, which occurs because a Media item doesn't get the updated MediaType. We have seen a similar issue with Document and DocumentTypes. An update and test in changeset 6a5a7221ac58

Let me know if you have time to try it out when a new build is ready.


Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.0

Due in version:

Sprint:

Story Points:

Cycle: