0
votes

We recently updated our development web site from Sitecore CMS 6.6 to Sitecore CMS 7.2. Upon doing so, we lost the ability to load any page on the site that contains an image (almost all of them!), returning the stack trace error:

[MissingMethodException: Method not found: 'System.String Sitecore.Data.Fields.ImageField.get_Src()'.]

[TargetInvocationException: Property accessor 'ImgURL' on object 'Siteworx.Domain.Modules.HomeCarousel' threw the following exception:'Method not found: 'System.String Sitecore.Data.Fields.ImageField.get_Src()'.']

Now currently, the code that we have that is supposed to generate the Image URL (and was working up until the update) is as follows:

public string ImgURL
{
    get { return new SCTypes.Image(this, "image").URL; }
}

I am having problems with figuring out what is going wrong here, and have, thus far, had little luck finding any decent references on this issue. If someone could please pull me in the right direction, I would be forever appreciative.

UPDATE - 8/20/2014

Okay,

So I updated the above code to:

public string ImgURL
    {

        //get { return new SCTypes.Image(this, "image").URL; }
        get
        {
            string src = string.Empty;

            Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
            Sitecore.Data.Items.Item HomeCarousel = master.GetItem("/sitecore/content/modules/home/carousel items");
            Sitecore.Data.Fields.ImageField imageField = HomeCarousel.Fields["imagefield"];

           if (imageField != null && imageField.MediaItem != null)
            {
                Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem);
                src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));
               // src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(image);
           }

            return src;

        }

And the page now loads, but without images. When viewing the html for where the image should be, I see:

<img src = "">

Which means that the URL for the image is not getting set within the IF Statement. When I try build the code without the IF Statement and load the page, StackTrace pulls back a null reference error.

2

2 Answers

0
votes

Um. If you build it without the IF statement and you end up with a null reference error, it simply means that either imageField and/or imageField.MediaItem are indeed null. That IF statement simply allows it to test for null and return the empty string, which it is succeeding in doing!

As a result, this indicates that the problem is further back. I'm not a Sitecore dev & don't know the API, so I'm depending on a few minutes of research here...but I see one thing from the Sitecore Content API Cookbook:

Your "master.GetItem("/sitecore/content/modules/home/carousel items");" might need to be "master.GetItem("/sitecore/content/modules/home/carousel");" for the rest of it to grab the necessary details. See Section 3.4 "How to Access Media Items".

Good luck!

0
votes

Okay, so it turns out that I had the correct code, just in the wrong place. The two lines:

Sitecore.Data.Items.MediaItem image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem);
src = Sitecore.StringUtil.EnsurePrefix('/', Sitecore.Resources.Media.MediaManager.GetMediaUrl(image));

were needed in a separate "helper" code file where the code return this._imageField.Src; was located, which works to bring back all images, site-wide. It was the .Src that had been deprecated, and when replaced by the two lines, along with reverting the original code that was thought to be problematic get { return new SCTypes.Image(this, "image").URL; } the issue was solved.