Skip to main content

Cannot convert lambda expression to type X because it is not a delegate type

Error Description

This error can occur when an operator, expression, or property definition is not valid. As a result, the View Engine cannot recognize the entire extension definition (the lambda expression).

Usually, problematic syntax constructions look as follows:

Some_Class.Some_Property = [No_Namespace]Some_Non_Primitive_Type;

Solution 1

Make sure that all required namespaces are registered. Refer to the following section for more information: Manual Integration into an Existing Project.

For instance, register the System.Web.UI.WebControls namespace if you use the Orientation enumeration.

<configuration>
  <system.web.webPages.razor>
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.UI.WebControls" />
        ...
@Html.DevExpress().Menu(settings => {  
    ...  
    settings.Orientation = Orientation.Horizontal;  
}).GetHtml()  

Note that if you use DevExpress Project Templates to create a project, all required information is automatically added to the configuration files.

Solution 2

Use the full type name, including the namespace.

@Html.DevExpress().Menu(settings => {  
    ...  
    settings.Orientation = System.Web.UI.WebControls.Orientation.Horizontal;  
}).GetHtml()  

See Also

Compile Views in ASP.NET MVC