Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 334 posts 933 karma points
    Oct 26, 2016 @ 08:33
    Paul Griffiths
    0

    Razor visual studio IntelliSense not working for dynamic objects

    Hi everyone,

    I had some trouble with my visual studio 2013 professional edition last week which meant I had to reinstall the software. I have set everything back up and I have noticed that the IntelliSense is not working in my razor files for dynamic objects. I may be wrong but I could of swore this used to work prior to the reinstallation of VS.

    Consider the following code

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        //gets the home page using doc type alias (root node)
        var siteRoot = Model.Content.AncestorOrSelf("homePage");
        //gets the about us page using doc type alias
        var portfolioPage = siteRoot.Descendant("portfolioPage");
        //gets the gallery page using doc type alias
        var galleryPage = siteRoot.Descendant("galleryPage");
    
        var imagesToDisplay = portfolioPage.HasValue("imageAmount") ? portfolioPage.GetPropertyValue<int>("imageAmount") : 2;
    }
    
        <!-- .container -->
        <div class="container">
            <div class="post-heading-center">
                <h2>@(portfolioPage.HasValue("heading") ? portfolioPage.GetPropertyValue("heading") : portfolioPage.Name)</h2>
            </div>
            <nav>
                <a>All Work</a>
                <!--get gallery albums-->
                @foreach (var type in galleryPage.Children)
                {
                    var galleryAlbum = Umbraco.Media(type.GetPropertyValue<int>("image"));
    
                    if (galleryAlbum.ChildrenAsList.Count() != 0)
                    {
                      <a href="#" data-filter=".class-@type.Id">@type.Name</a>
                    }
                }
            </nav>
        </div>
    

    when using visual studio IntelliSense i get no options and a message informing me that its a dynamic expression and it will be resolved at runtime

    enter image description here

    I have resharpher ultimate installed and when i go to resharper > options and switch to the resharper IntelliSense i get the members from object and what looks like members that i have used elsewhere but resharper is not quite sure.

    enter image description here

    I know that the ChildrenAsList member (which is what i need) is available to the dynamic galleryAlbum object but why doesnt my IntelliSense tell me this.

    enter image description here

    The other thing that i have noticed is that my IntelliSense constantly stops working regardless if its in vs or resharper mode which also makes me believe something is screwed with this install. To fix i either have to close the code file or teh project itself. So with the above in mind i have the following questions

    1. Is it standard behaviour for vs IntelliSense not to work with dynamic objects in umbraco razor views?
    2. Why do base object members show when using resharper IntelliSense and not when using VS IntelliSense?
    3. Why does all IntelliSense constantly stop working?

    If anyone has any info on the above then i would be really greatful. I have attempted to reset all user settings via the import and export wizzard but had no luck

  • Jason Vickers 21 posts 115 karma points
    Nov 03, 2016 @ 01:24
    Jason Vickers
    100
    1. I have never had intellisense for dynamic objects. Think about it this way, how is VS or Resharper supposed to infer the properties of an object that is essentially a ghost until it receives values? This is why I usually strongly type anything coming into the page, even CurrentPage to var currentPage = (IPublishedContent)CurrentPage. Just makes debugging a lot easier.

    2. VS Intellisense, while a great tool, is hard to compare to a product that has focused on that functionality as one of it's major attributes that it can charge for.

    3.Personally, I have ran into this issue a couple of times. Usually restarting VS or refreshing the Resharper cache fixes it for me.

  • Paul Griffiths 334 posts 933 karma points
    Nov 19, 2016 @ 22:07
    Paul Griffiths
    0

    Thanks Jason,

    All that information is really useful. I'll mark as the solution 😄

Please Sign in or register to post replies

Write your reply to:

Draft