searchResult.Evaluate causing exception 'object' does not contain a definition for 'Evaluate'

Jul 29, 2016 at 5:47 PM
Hi all,

I am developing an Umbraco 7 MVC web site and so assume that I should convert FullTextSearchPage.master and the FullTextSearch.cshtml Umbraco Macro, to use a Partial View instead. In doing this I am moving most of the code from FullTextSearch.cshtml into a Partial View.

When doing this the line of code indicated with comment "// <<<<<" below is causing an exception:
            @foreach (var searchResult in resultsItem.Current.Select("/results/nodes/*"))
                var fullTextId = searchResult.Evaluate("string(./@id)");  // <<<<<<<<<
                var fullTextTitle = searchResult.Evaluate("string(./data [@alias='FullTextTitle'])");
                var fullTextSummary = searchResult.Evaluate("string(./data [@alias='FullTextSummary'])");
The exception is
System.Web.HttpCompileException was unhandled by user code
  Message=c:\Clancy\A_TeraTastic\Dev\TeraTastic09\TeraTastic\Views\Partials\TTPV_30_10_Search_UmbFullText.cshtml(221): error CS1061: 'object' does not contain a definition for 'Evaluate' and no extension method 'Evaluate' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
       at System.Web.Compilation.AssemblyBuilder.Compile()
       at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
       at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
"searchResult" seems to be of type "Object" and thus has no interesting, application defined methods or properties. It does not not contain a defnition for 'Evaluate' . Thus an exception is through at the attempted reference to searchResult.Evaluate.

If anyone can help me understand how to resolve this it would be very much aappreciated.


Terry Clancy
Jul 29, 2016 at 9:43 PM
Hi again :-)

OK, so I have solved this problem. It is not clear to me why these changes were needed, ie why different syntax was needed in Razor Partial View v Umbraco Razor Macro, but in any case I solved the issued but changes in the lines marked with the comment "// <<<<<<<" below:
    @if (int.Parse((results.Current.Evaluate("count(/results)")).ToString()) == 1)     // <<<<<<<  Needed to use int.Parse and ToString rather than (int) cast
        var resultsItem = results.Current.Select("/results");
        <div class="fulltextsearch_results">
            <h4 class="fulltextsearch_results_heading">@String.Format(GeneralExtension.DictionaryHelper("SearchResultsFor"), searchTerms)</h4>
                var numPages = (int)resultsItem.Current.Evaluate("number(/results/summary/@numPages)");
            @if (numPages > 1)
                @Pagination(numPages, pageNumber, getPostTerms, searchTermsUrlEncoded, getPostPage, numNumbers)

            @foreach (XPathNavigator searchResult in resultsItem.Current.Select("/results/nodes/*"))    // <<<<<<<  Needed to explicitly specify type XPathNavigator  rather than var
                string fullTextId = (string)searchResult.Evaluate("string(./@id)");    // <<<<<<<   Needed to explicitly specify type string and add cast to string
                string fullTextTitle = (string)searchResult.Evaluate("string(./data [@alias='FullTextTitle'])");      // <<<<<<<   Needed to explicitly specify type string and add cast to string
                string fullTextSummary = (string)searchResult.Evaluate("string(./data [@alias='FullTextSummary'])");      // <<<<<<<   Needed to explicitly specify type string and add cast to string

                <div class="fulltextsearch_result">
                    <p class="fulltextsearch_title">
                        <a class="fulltextsearch_titlelink" href="@umbraco.library.NiceUrl(int.Parse(fullTextId))">@Html.Raw(fullTextTitle)</a>
                    <p class="fulltextsearch_summary">@Html.Raw(fullTextSummary)</p>
I hope this helps someone :-)

Terry Clancy
Marked as answer by terryclancy on 7/29/2016 at 2:43 PM