Copied to clipboard

Flag this post as spam?

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


  • Neil 63 posts 105 karma points
    May 01, 2014 @ 15:24
    Neil
    0

    Razor script errors after upgrading from 4.7 to 6.1.6

    I have inherited a site that I'm trying to upgrade from umbraco 4.7 to 6.1.6.  Everything's gone well, but I have a bunch of cshtml razor scripts that are throwing errors when they worked fine in the older version of umbraco.  I'm wondering if, in upgrading, that the processing of the scripts works differently in the newer version and the syntax of the older scripts is no longer compatible.  Can anyone tell me how I can tell if this is the case or if it's something else?

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    May 01, 2014 @ 16:40
    Jan Skovgaard
    0

    Hi Neil

    The Razor implementation has changed between versions. Originally version 4.7.x of Umbraco was supposed to be the last since v5 was in the making. But as you might know it got canned and development continued with v4 so v4.8 to v4.11.x was released untill v6 was ready last year around this time. So A LOT has happened under the hood between versions.

    So could you give us some examples of the errors you're seeing now? And did you follow the upgrade documentation here http://our.umbraco.org/documentation/Installation/Upgrading/ ?

    /Jan

  • Neil 63 posts 105 karma points
    May 01, 2014 @ 17:29
    Neil
    0

    Hi Jan,

    I did not follow the upgrade instructions there.  I did a clean install of 6.1.6, and let NuGet update packages where I could before porting the old code (including all our cshtml scripts).  Here's an example of one that is broken now:

    this bit of code:

            foreach (var item in nodeIdList)
            {
                <li>
                    @try
                    {
                        var HARDCODED_Home_Aboutus_Press = 1147;
                        var pressUrl = (new DynamicNode(HARDCODED_Home_Aboutus_Press)).Url;
                        var node = Model.NodeById(item);
                        var date = node.pressReleaseDate.ToString("MM/dd/yyyy");
                        <span>@date</span>
                        @WilshireHelpers.RenderPressLink(node, pressUrl)
                    }
                    catch (Exception ex)
                    {
                        @ex.Message
                    }
                </li>
            }


    calls this helper function:

    @helper RenderPressLink(dynamic pressNode, string pressUrl){

      var link = string.Empty;
        var newWindow = string.Empty;
        if (!string.IsNullOrEmpty(pressNode.pressReleaseLink)) {
        string[] lnk = pressNode.pressReleaseLink.Split(',');                
            if(lnk[1].ToLower() == "true") { newWindow = " target=\"__blank\"";}  
            if(lnk[0] == "Content") {
              if(!string.IsNullOrEmpty(lnk[2])) { link = pressUrl + "?id=" + pressNode.Id.ToString(); }              
            } else {
              if(!string.IsNullOrEmpty(lnk[3])) { link = lnk[3]; }
            }                                    
          }
          <a href="@link">@pressNode.pressReleaseTitle</a>                                                                                  
    }

    which produces this error on the page:

        Could not load type 'Xml' from assembly 'uComponents.Core, Version=3.0.2.1, Culture=neutral, PublicKeyToken=null'.

    What it appears is that while it grabs the node in the original function using Model.NodeById(item), that when trying to access document properties in that node in the helper function call to @pressNode.pressReleaseTitle it fails.  I worked around this in another area where I had a similar issue by not trying to get the property directly with a node.property syntax but instead used node.GetProperty("property_name").Value or node.GetPropertyValue("property_name").  That said, I'd rather not hack each script to do this, and want to know what the right/clean solution to the problem is.

     

     

     

     

     

  • Charles Afford 1163 posts 1709 karma points
    May 05, 2014 @ 17:53
    Charles Afford
    0

    No sure if this sounds silly but can you assert that all of the code works?  I.E not null and all of the properties RenderPressLink() are correct and not errroing. Is ink[] not String.Empty?

    Also why is you paramter 'dynamic'?  You will lose all intellisense?

    Charlie :)


  • Neil 63 posts 105 karma points
    May 19, 2014 @ 16:26
    Neil
    0

    Hi Charlie,

    The only thing I can attest to is that the scripts worked against the same dataset when running umbraco 4.7.  As for the parameter, I'm not all that familiar with .cshtml scripting yet, since I inherited this code, so can't say one way or another why coding choices were made. :-)

Please Sign in or register to post replies

Write your reply to:

Draft