The call is ambiguous between the following methods or properties: ‘Umbraco.Web.UmbracoHelper.Media

I was coding up a new template in the latest version of Umbraco v7 using Razor and discovered this error when trying to get a Media object from one of my properties of the current page.


The call is ambiguous between the following methods or properties: ‘Umbraco.Web.UmbracoHelper.Media(params int[])’ and ‘Umbraco.Web.UmbracoHelper.Media(params string[])’

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: The call is ambiguous between the following methods or properties: ‘Umbraco.Web.UmbracoHelper.Media(params int[])’ and ‘Umbraco.Web.UmbracoHelper.Media(params string[])’

My property was a Media Picker type which I made the assumption it was given me a Integer Node Id to the specific media object.

I started out with the following code:

1
@Umbraco.Media(CurrentPage.ProfileImage).umbracoFile

This caused the error above, so by converting it to a string using the .ToString() method, this caused the compiler to ignore the error and use the correct UmbracoHelper method.

1
@Umbraco.Media(CurrentPage.portfolio5Image.ToString()).umbracoFile

hexadecimal value 0x1F, is an invalid character publishing content in Umbraco

I was adding some content into a Umbraco content page when I attempted to publish the page I got a 500 error with the following error message:

1
2
3
4
5
6
7
8
9
10
Server Error in '/' Application.

'', hexadecimal value 0x1F, is an invalid character. Line 1, position 519.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Xml.XmlException: '', hexadecimal value 0x1F, is an invalid character. Line 1, position 519.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

The issue was because of a special/invalid character in the content. This may be caused by copy and paste from a application like Microsoft Word or a similar word processing application. The best way to get around this is to paste the content into a application like Notepad or Notepad++ and then find the invalid character, replace the character and then copy/paste into Umbraco.

Get All Nodes By DocumentType

The following code describes how to get all the nodes by a particular document type across the whole Umbraco site. It uses a recursive method so if you add this as a macro I would suggest caching to reduce the number of times this method runs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.presentation.nodeFactory;


public class UmbracoHelper
{
    private const int CONST_NODEAMOUNT = 10;
    /// <summary>
    /// Get all nodes by type, put -1 to start at the root of the website
    /// </summary>
    /// <param name="NodeId"></param>
    /// <param name="typeName"></param>
    /// <returns></returns>
    public static List<Node> GetAllNodesByType(int NodeId, string typeName)
    {
        List<Node> foundNodes = new List<Node>();
        var node = new Node(NodeId);
        foreach (Node childNode in node.Children)
        {
            var child = childNode;
            if (child.NodeTypeAlias == typeName)
            {
                foundNodes.Add(child);
            }

            if (child.Children.Count > 0)
                GetAllNodesByType(ref foundNodes, child, typeName);
        }

        //Take the first 10, this can be changed
        return foundNodes.Take(CONST_NODEAMOUNT).ToList();
    }

    /// <summary>
    /// Recursive method to get the nodes from the child passed in as a parameter
    /// </summary>
    /// <param name="foundNodes"></param>
    /// <param name="node"></param>
    /// <param name="typeName"></param>
    private static void GetAllNodesByType(ref List<Node> foundNodes, Node node, string typeName)
    {
     
        foreach (Node childNode in node.Children)
        {
            var child = childNode;
            if (child.NodeTypeAlias == typeName)
            {
                foundNodes.Add(child);
            }

            if (child.Children.Count > 0)
                GetAllNodesByType(ref foundNodes, child, typeName);
        }
    }

   
    public UmbracoHelper()
    {
       
    }
}

Script error when using RichTextEditor type in Razor macro – Umbraco

I came across this issue when trying to check if the RichTextEditor property had any content before rendering it to the display.

Examine the following code:

1
2
3
4
5
6
7
8
9
@{
var thisNode = Model;

}

@if (!string.IsNullOrEmpty(thisNode.MyRichContent))
{
<div class="text-widget">@thisNode.MyRichContent</div>
}

This causes a script error because Umbraco thinks MyRichContent is a object type.
To get around this, either call .ToString() on the property or do a length condition i.e thisNode.MyRichContent.ToString().Length > 0 to resolve the issue.