Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 10:33
    Jason Espin
    0

    Parsing error in Umbraco 7 partial view : missing closing brace despite all brace pairs being present

    I'm currently working on trying to get to grips with Umbraco and the use of Razor however i'm finding the inline nature of the Razor code particularly difficult. For some reason, when I compile my partial view below (which outputs a Bootstrap carousel to the screen on the page in which it is called) i'm getting the following compilation error:

    Line 3:  @if (Model.Content.HasValue("bannerImages")){  
    Parser Error Message: The if block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.
    

    However I've checked all of my tags in Notepad++ (as this is better at identifying matching tags that Visual Studio) and all of the braces in my document tie up so this leads me to believe that I may be implementing some of the inline Razor code blocks incorrectly. Any ideas?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @if (Model.Content.HasValue("bannerImages")){   
        var bannerImagesList = Model.Content.GetPropertyValue<string>("bannerImages").Split(new string[]{","}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
        var bannerImagesCollection = Umbraco.TypedMedia(bannerImagesList).Where(x => x != null);
        var imageCount = 0;
    
        <div id="carousel" class="carousel slide" data-ride="carousel">
          <!-- Indicators -->
          <ol class="carousel-indicators">
            <li data-target="#carousel" data-slide-to="0" class="active"></li>
            <li data-target="#carousel" data-slide-to="1"></li>
            <li data-target="#carousel" data-slide-to="2"></li>
            <li data-target="#carousel" data-slide-to="3"></li>
          </ol>
    
          <!-- Wrapper for slides -->
          <div class="carousel-inner">
            @foreach (var bannerImage in bannerImagesCollection){
                if (@imageCount < 1){
                    <div class="item active">
                }else{
                    <div class="item">
                }
                        <img src="@bannerImage.Url" alt="@bannerImage.Id" />
                    </div>
            }
          </div>
        </div>  
    }
    
  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Apr 11, 2014 @ 10:42
    Jan Skovgaard
    0

    Hi Jason

    Sometimes those YSOD's can show messages that are not entirely true...if for instance something should be made to a string or casted to something else.

    I'm not that good a razor yet and I feel terified each time I see a ysod that makes no sense to me. But during the past days I've experienced that sometimes it happens if the code is in a "wrong" context or if I forget to add .ToString() to something.

    Don't know if you perhaps need to add bannerImagesCollection.ToString() for instance.

    /Jan

  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 11:01
    Jason Espin
    0

    After asking the same question on Stack Overflow it would appear that Razor isn't intelligent enough to recognise the shared closing div tag that is used as for either of the cases. I've therefore refactored my code into the following:

     <!-- Wrapper for slides -->
        <div class="carousel-inner">
            @foreach (var bannerImage in bannerImagesCollection){
                var cssClass = imageCount < 1 ? "item active" : "item";
    
                <div class="@cssClass">
                    <img src="@bannerImage.Url" alt="@bannerImage.Id" />
                </div>
            }
        </div>
    

    However, I'm now getting a valueDictionary error.

    Line 19:                 var cssClass = imageCount < 1 ? "item active" : "item";
    Exception Details: System.FormatException: The valueDictionary is not formatted correctly and is missing any of the  'id,nodeId,__NodeId' elements
    

    Is this because Umbraco cannot use the variable I have declared within the partial view?

  • Carsten Fallesen 35 posts 154 karma points
    Apr 11, 2014 @ 11:05
    Carsten Fallesen
    1

    Hi Jason,

    I believe your problem is the check for imageCount. There are actually two issues the:

    1. Inside the code scope you should not use @imageCount, just imageCount

    2. In the latest Razor version you can't use split the opening div ike this. You can set the class value in a variable before the opening div tag and then apply it in the opening div tag.

    I hope this gets you in the right direction.

    /Carsten

     

  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 11:12
    Jason Espin
    0

    Hi Carsten,

    This is what I have done in my reply above but I am still getting the dictionary error.

    Jason

  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 11:20
    Jason Espin
    101

    It appears that there is some strange caching going on in Umbraco / Visual Studio. If I go to App_Data/Temp/ExamineIndexes folder and delete all the files from Index folders in there it fixes the issue. Any ideas why this has happened?

  • Carsten Fallesen 35 posts 154 karma points
    Apr 11, 2014 @ 11:26
    Carsten Fallesen
    0

    Hi Jason,

    My previous reply must have crossed reply, but glad you worked it out on your own.

    I have seen a similar issue in the thread http://our.umbraco.org/forum/developers/api-questions/44851-Issue-With-Media-Cache-in-v6

    Maybe you're seeing something similar, although on v7? Are you at the latest version (7.1.1.)?

    /Carsten

  • Jason Espin 368 posts 1335 karma points
    Apr 11, 2014 @ 11:59
    Jason Espin
    0

    Hi Carsten,

    I am indeed using the latest version. It's my first time using Umbraco so not aware of any issues in previous versions but this has definitely resolved this issue for me this time around.

    /Jason

  • Dalain 2 posts 22 karma points
    Jul 21, 2014 @ 22:47
    Dalain
    0

    Hi Jason,

    Have you discovered a solution to your issue? I am encountering something similar with Media/Caching in v7.

    Thanks

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Aug 20, 2014 @ 12:40
    Steve Morgan
    0

    Just had this happen - bit of code that had been working fine with media image suddenly threw "The valueDictionary is not formatted correctly and is missing any of the 'id,nodeId,__NodeId' elements" - clearing out the index folders in the  App_Data/Temp/ExamineIndexes subfolders sorted it. (Thanks Jason!)

    I wonder why!? 

  • Ian Black 54 posts 230 karma points
    Oct 29, 2014 @ 10:52
    Ian Black
    0

    Does anyone have any more information on this error?

    I keep receiving it randomly on a production website. The only way to fix it is a combination of deleting the contents of the TEMP folder, republishing the entire site, republishing using /umbraco/dialogs/republish.aspx?xml=true or restarting the app pool.

  • Braydie 148 posts 346 karma points
    Nov 17, 2014 @ 15:55
    Braydie
    0

    I'm seeing this in a production site too. Currently running 6.2.4

  • Mike 35 posts 100 karma points
    Nov 21, 2014 @ 18:34
    Mike
    0

    Also just received this message: two times in the past two days. Never had it before.

    I've asked our admin and project manager the following questions:

    Were any pushes done today?   EDIT: None. 

    Did the app pool recycle because of high memory?  EDIT:  No.

    What lead up to this?  EDIT:  Seems to happen randomly. It just happened twice today (on production).

    I'll report back when I get the answers above, but please let me know if you think there are more questions that I can ask OR if anyone has a solution that prevents this from happening rather than a solution to resolve it when it happens (such as recycling the app pool)

     

  • Jonas 123 posts 206 karma points
    Dec 01, 2014 @ 10:52
    Jonas
    0

    I am seeing this in a site and its Umbraco version 7.1.8 assembly: 1.0.5394.16131

    Clearing the indexes helped.

  • Paul Aikman 43 posts 97 karma points
    Dec 04, 2014 @ 17:48
    Paul Aikman
    0

    Hi,

    Did anyone get any further with why this is happening/potential fixes? Seems to happen periodically on a lot of our Umbraco 6.x sites.

    Thanks,

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft