Copied to clipboard

Flag this post as spam?

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


  • Stefan 117 posts 215 karma points
    Aug 28, 2013 @ 22:21
    Stefan
    0

    Fails to load Multi Language Tools razor macro

    I'm experiencing some errors when navigating to pages that have related nodes. I have followed this great article to be able to access the nodes that have been picked from another node (http://24days.in/umbraco/2012/who-picked-this/).

    The error is only showing when a node is actually picked (and published) regarding if the current page is the one that has the picker or if its the node being picked. Whenever navigating to one of those nodes, the razor script for Multi Language Tools fails.

    The error is noticeable by the razor macro not loading. Here is what I see when providing the query string ?umbDebugShowTrace=true:

    Error Loading Razor Script (file: ) An item with the same key has already been added.    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
      at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
      at ASP.MultiLanguage.Functions.GetChildren(Int32 id, Relation[] relations)
      at ASP.MultiLanguage.Functions.GetUrlsAndLanguages(Int32 nodeid)
      at ASP._Page_macroscripts_MultiLanguage_LanguageSwitcher_LSM_cshtml.Execute() in c:\Users\Stefan\Documents\My Web Sites\LSM\macroScripts\MultiLanguage\LanguageSwitcher\LSM.cshtml:line 3
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
      at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
      at System.Web.WebPages.WebPage.ExecutePageHierarchy()
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
      at System.Web.WebPages.WebPageBase.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer)
      at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
      at System.Web.WebPages.WebPageBase.Write(HelperResult result)
      at ASP._Page_App_Data_TEMP_Razor_inline_16e7cb6c0c341e497d5191837ee956eb_cshtml.Execute() in c:\Users\Stefan\Documents\My Web Sites\LSM\App_Data\TEMP\Razor\inline-16e7cb6c0c341e497d5191837ee956eb.cshtml:line 1
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
      at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
      at System.Web.WebPages.WebPage.ExecutePageHierarchy()
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
      at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
      at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
    Error loading MacroEngine script (file: , Type: ''
    An item with the same key has already been added.
      at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
      at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
      at ASP.MultiLanguage.Functions.GetChildren(Int32 id, Relation[] relations)
      at ASP.MultiLanguage.Functions.GetUrlsAndLanguages(Int32 nodeid)
      at ASP._Page_macroscripts_MultiLanguage_LanguageSwitcher_LSM_cshtml.Execute() in c:\Users\Stefan\Documents\My Web Sites\LSM\macroScripts\MultiLanguage\LanguageSwitcher\LSM.cshtml:line 3
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
      at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
      at System.Web.WebPages.WebPage.ExecutePageHierarchy()
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
      at System.Web.WebPages.WebPageBase.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer)
      at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
      at System.Web.WebPages.WebPageBase.Write(HelperResult result)
      at ASP._Page_App_Data_TEMP_Razor_inline_16e7cb6c0c341e497d5191837ee956eb_cshtml.Execute() in c:\Users\Stefan\Documents\My Web Sites\LSM\App_Data\TEMP\Razor\inline-16e7cb6c0c341e497d5191837ee956eb.cshtml:line 1
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
      at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
      at System.Web.WebPages.WebPage.ExecutePageHierarchy()
      at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
      at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
      at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
      at umbraco.macro.loadMacroScript(MacroModel macro)
      at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
    

    I'm currently at Umbraco version 6.1.4 (latest release) but 6.1.3 gave the same error. I have no clue if Multi Language Tools is the actual cause, but since its the only macro (razor) script failing, I have a hunch that it must be the cause.

    Any help is greatly appreciated, especially since the site is about to be launched this weekend :)

    Edit:

    I have just tried to remove the inline razor used to add the language switcher and add the macro instead. This gives the same error. Also, when removing the Language Switcher from my template no errors are found in the StackTrace.

  • Stefan 117 posts 215 karma points
    Aug 30, 2013 @ 15:21
    Stefan
    101

    I think I've found a solution. Not sure if something on my site is the cause of the error. I digged into the Functions.cshtml file, and added a check before a language and child are added to the dictionary.

    // match nodes with languages and return result
    Dictionary<int, int> dictionary = new Dictionary<int, int>();
    foreach (int child in children)
    {
        int langid = GetLanguageIdFromNodeId(child);
        if (langid != 0 && !dictionary.Keys.Contains(langid))
        dictionary.Add(langid, child);
    }
    return dictionary;
    

    Its the snippet && !dictionary.Keys.Contains(langid)

    Please let me know if this is a stupid solution ;)

  • Oliver 5 posts 45 karma points
    Feb 06, 2014 @ 14:36
    Oliver
    0

    Works great!

Please Sign in or register to post replies

Write your reply to:

Draft