Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Asad Kizzie 28 posts 158 karma points
    Oct 13, 2020 @ 19:10
    Asad Kizzie
    0

    Namespace Error While Trying to Upgrade - The type or namespace name 'Image' could not be found.

    Alrighty -

    I'm working locally on my computer to test the upgrade process. I had version 7.1.8 working well on my computer so I followed the upgrade steps to try and install version 7.15.6.

    I'm now trying to compile and run the website through Visual Studio 2019 and I'm recieving a few errors.

    This is the error message:

    The type or namespace name 'Image' could not be found (are you missing a using directive or an assembly reference?)

    and it is occurring multiple times on my Gallery.cshtml page. I have provided a copy of that below.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Web
    @using Umbraco.Web.PublishedContentModels
    @{ var mediaIds = Model.MacroParameters["mediaIds"] as string; }
    @if (mediaIds != null)
    {
    <div class="row">
        @foreach (var mediaId in mediaIds.Split(','))
        {
            var media = Umbraco.TypedMedia(mediaId);
    
            @* a single image *@
            if (media.DocumentTypeAlias == "Image")
            {
                @Render(media as Image);
            }
    
            @* a folder with images under it *@
            foreach (var image in media.Children<Image>())
            {
                @Render(image);
            }
        }
    </div>
    }
    @helper Render(Image item)
    {
    <div class="col-xs-6 col-md-3">
        <a href="@item.Url" class="thumbnail">
            <img src="@item.GetCropUrl(width:200, height:200)" alt="@item.Name" />
        </a>
    </div>
    }
    

    I'm not sure what to do! Any ideas?

  • Marc Goodson 2157 posts 14431 karma points MVP 9x c-trib
    Oct 15, 2020 @ 05:56
    Marc Goodson
    0

    Hi Asad

    The Image class that you refer to in your template is I think a Modelsbuilder 'generated' C# class, you have the namespace: @using Umbraco.Web.PublishedContentModels referenced which is where Modelsbuilder will generate it's models.

    So something might have changed with Modelsbuilder but if you've just done an upgrade - the first thing to check is that the configuration for Modelsbuilder in your project remains the same.

    If you are referring to the generated Models in your Visual Studio project, then they will need to be generated in AppData mode, rather than Pure live - so check your Web.Config appsettings for Modelsbuilder to see if it is turned on and which mode it is running in.

    If you are happy it's in the same mode as before, then make sure that the Models have been 'generated' for your upgraded site, visit the Setting section in the backoffice and find the Modelsbuilder dashboard - there should be an option to generate models here.

    This should generate files on disk in the projects app_data folder (if running in appdata mode) - look for a generated Image class to confirm - then these files would need to be included in the Visual Studio project for you to be able to reference them locally and get intellisense etc

    Failing that you don't appear to be doing anything that would need to use the generated properties of the Image, so you could replace Image in your view with IPublishedContent instead, as this has the Name, Url and GetCropUrl properties/extensions that you are using to write out the image details...

    regards

    marc

  • Asad Kizzie 28 posts 158 karma points
    Oct 15, 2020 @ 14:26
    Asad Kizzie
    0

    Thank you @marc! I also realized that by default Visual Studio excludes many folders from the solution for build when installing Umbraco through NuGet. For this instance, I created the project through a .zip file and left all of the folders as part of my solution. Once I excluded the folder from my project (along with a few others), I was able to rebuild and run the website without any error messages.

Please Sign in or register to post replies

Write your reply to:

Draft