I'm using Umbraco 13.2.2 and trying to migrate a macro to a block, and getting an "Object reference not set to an instance of an object" error.
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Umbraco.Cms.Core.Models.Blocks.RichTextBlockItem>
@{
var folderId = Model.Content.Value("mediaFolderID");
var media = Umbraco.Media(folderId);
var selection = media.Children().OfType<Image>();
}
The media.Children().OfType<Image>(); line is causing the object reference error, but I'm not sure why as I'm using the Media Picker to get mediaFolderID.
I resolved the error by specifying the type, IPublishedContent, of the model value. And then I had to get the Id of the folder, rather than the whole object:
var folderId = Model.Content.Value<IPublishedContent>("mediaFolderID");
var media = Umbraco.Media(folderId.Id);
Problem Migrating Macros to Blocks
I'm using Umbraco 13.2.2 and trying to migrate a macro to a block, and getting an "Object reference not set to an instance of an object" error.
The
media.Children().OfType<Image>();
line is causing the object reference error, but I'm not sure why as I'm using the Media Picker to get mediaFolderID.I resolved the error by specifying the type, IPublishedContent, of the model value. And then I had to get the Id of the folder, rather than the whole object:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.