An exception of type 'System.ArgumentException' occurred in cms.dll but was not handled in user code

StackOverflow https://stackoverflow.com/questions/22155746

  •  19-10-2022
  •  | 
  •  

Question

Trying to go to a page on my site, got a blank screen and decided to try again with Visual Studio 2012 loaded and debugging it, now I get this error when the page loads:

An exception of type 'System.ArgumentException' occurred in cms.dll but was not handled in user code and points to the following code in HeaderControl.ascx.cs:

else if(new umbraco.cms.businesslogic.template.Template((Context.GetContent()).template).Alias == "TemplateLanguage")

This code is inside the following method:

public void LoadData()
{
    _Location = HttpContext.Current.GetLocation();

    if (Context.GetContent().NodeTypeAlias == "Home")
    {
        TheHomeHeaderPH.Visible = true;
        ThePhonePH.Visible      = true;
        _MenuStyle = "var-nav nav-large";
        LoadMenuTopControl();
        LoadMenuMainControl();
    }  
    else if(new umbraco.cms.businesslogic.template.Template((Context.GetContent()).template).Alias == "TemplateLanguage") 
    {
        TheContentHeaderPH.Visible = true;
        _MenuStyle              = "nav-small";
        LoadContentMenuTopControl();
        LoadMenuLanguageControl();
    }
    else
    {
        MMG.BusinessLayer.Content theContent = MMG.BusinessLayer.Content.GetCached(Context.GetContent());

        if (theContent.TemplateColor == "168C9C")
        {
            TheHomeHeaderPH.Visible = true;
            _MenuStyle = "nav-small";
            LoadMenuTopControl();
            LoadMenuMainControl();
        }
        else
        {
            TheContentHeaderPH.Visible = true;
            LoadContentMenuTopControl();
            LoadContentMenuMainControl();
        }
    }
}

How can I fix this problem? System.ArgumentException says this: {"No node exists with id '0'"}

Was it helpful?

Solution

I would guess it's the (Context.GetContent()).template that breaks somehow and I assume GetContent is a custom extension method.

The exception {"No node exists with id '0'"} usually means that you couldn't fetch the node you requested.

Instead try

else if(new umbraco.cms.businesslogic.template.Template(umbraco.uQuery.GetCurrentNode().template).Alias == "TemplateLanguage")

If that doesn't work it means you are running the code in a context where the CurrentNode is unavailable. In that case you must extend your LoadData method with a nodeId parameter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top