The type or namespace name 'HTMLHelper' does not exist in the namespace 'CMS.GlobalHelper'

Sofia Khatoon asked on March 2, 2017 16:23

I am trying to configure Smart Search for Kentico 8.2 site. I placed the Smart Search with Results dialog on a page. I see the following error when I click on search icon

The type or namespace name 'HTMLHelper' does not exist in the namespace 'CMS.GlobalHelper'

Correct Answer

Brenden Kehren answered on March 2, 2017 17:02

Then prefex the ValidationHelper with Helpers.ValidationHelper

1 votesVote for this answer Unmark Correct answer

Recent Answers


Zach Perry answered on March 2, 2017 16:27 (last edited on March 2, 2017 16:27)

Was the site upgraded from 7 to 8? HTMLHelper was moved from GlobalHelper to Helpers.

If this wasn't a recent upgrade, you might have to install a fresh copy of 8.2 and replace the webpart in your solution, otherwise you need to make sure the upgrade was done properly.

0 votesVote for this answer Mark as a Correct answer

Sofia Khatoon answered on March 2, 2017 16:33 (last edited on March 2, 2017 16:34)

Hi Zach, Thank you for your answer but I can see that correct dll is referenced in the web part and the bin folder has CMS.Helpers.dll

using CMS.Controls;

using CMS.Helpers;

using CMS.PortalControls;

using CMS.SiteProvider;

using CMS.Membership;

using CMS.Search;

in file inetpub\KenticoCMS_Main\CMS\CMSWebParts\SmartSearch

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on March 2, 2017 16:38

Does your solution build successfully?

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on March 2, 2017 16:40

I would also check the control for the webpart \CMSModules\SmartSearch\Controls\SearchDialog.ascx.cs

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 2, 2017 16:42

If you upgraded your site from a version 7 site, you also needed to update the transformations. I'd suggest looking at the transformation that webpart is utilizing. Most likely there is a reference to the CMSContext class which is no longer valid in v8.

0 votesVote for this answer Mark as a Correct answer

Sofia Khatoon answered on March 2, 2017 16:46

Hi Brenden Thank you for the help. The full error message is

TempITemplate.Template]: http://server/CMSVirtualFiles/Transformations/=vg=1c8798a6-3265-418e-a0d1-876e6a5962a7/CMS.Root/SmartSearchResults.ascx(6): error CS0234: The type or namespace name 'HTMLHelper' does not exist in the namespace 'CMS.GlobalHelper' (are you missing an assembly reference?)[

I do not see any CMSVirtualFiles folder so I am not sure where to look for the CMSContext reference.

0 votesVote for this answer Mark as a Correct answer

Zach Perry answered on March 2, 2017 16:51

You can edit the transofrmation by going to page types, searching for root, and clicking transformations in the left menu, and finding the SmartSearchResults transformation. I believe this should be the default:

<div style="margin-bottom: 30px;">
    <%-- Search result title --%>
    <div>
        <a style="font-weight: bold" href='<%# SearchResultUrl() %>'>
            <%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>
      </a>
    </div>
    <%-- Search result content --%>
    <div style="margin-top: 5px; width: 590px;">
        <%#SearchHighlight(HTMLHelper.HTMLEncode(TextHelper.LimitLength(HttpUtility.HtmlDecode(HTMLHelper.StripTags(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(GetSearchedContent(DataHelper.GetNotEmpty(Eval("Content"), ""))), false, " ")), 280, "...")), "<span style='background-color: #FEFF8F'>", "</span>")%><br />
    </div>
    <%-- Relevance, URL, Creattion --%>
    <div style="margin-top: 5px;">
        <%-- Relevance --%>
        <div title="Relevance: <%# Convert.ToInt32(ValidationHelper.GetDouble(Eval("Score"), 0) * 100) %>%"
            style="width: 50px; border: solid 1px #aaaaaa; margin-top: 7px; margin-right: 6px; float: left; color: #0000ff; font-size: 2pt; line-height: 4px; height: 4px;">
            <div style='<%# "background-color:#a7d3a7;width:" + Convert.ToString(Convert.ToInt32(ValidationHelper.GetDouble(Eval("Score"), 0) * 50)) + "px;height:4px;line-height: 4px;" %>'>
            </div>
        </div>
        <%-- URL --%>
        <span style="color: #008000">
            <%# SearchHighlight(SearchResultUrl(),"<strong>","</strong>")%>
        </span>
        <%-- Creation --%>
        <span style="color: #888888; font-size: 9pt">
            <%# GetDateTimeString(ValidationHelper.GetDateTime(Eval("Created"), DateTimeHelper.ZERO_TIME), true) %>
        </span>
    </div>
</div>
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 2, 2017 16:59

Sofia, you need to look specifically in the webpart properties and look for the transformation. In there edit it and look for the CMSContext. The transformations aren't stored in the file system, they are stored in the database and you access them through the Kentico UI.

Still didn't answer the question, did you upgrade your site from version 7?

0 votesVote for this answer Mark as a Correct answer

Sofia Khatoon answered on March 2, 2017 16:59

I am getting the following error when I apply this transformation

http://server/CMSVirtualFiles/Transformations/=vg=73624711-6ec0-43b4-bd32-46407b72e3ef/CMS.Root/SmartSearchResults.ascx(16): error CS0104: 'ValidationHelper' is an ambiguous reference between 'System.Web.WebPages.ValidationHelper' and 'CMS.Helpers.ValidationHelper'

0 votesVote for this answer Mark as a Correct answer

Sofia Khatoon answered on March 2, 2017 17:21

Thanks Brenden, I am getting the following error when I apply this change

http://server/CMSVirtualFiles/Transformations/=vg=6a5899fa-8d3e-46b2-aa5a-6dd073250286/CMS.Root/SmartSearchResults.ascx(16): error CS0103: The name 'Helpers' does not exist in the current context

My transofrm looks as below

<%-- Search result title --%> <%-- Search result content --%>
<%#SearchHighlight(HTMLHelper.HTMLEncode(TextHelper.LimitLength(HttpUtility.HtmlDecode(HTMLHelper.StripTags(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(GetSearchedContent(DataHelper.GetNotEmpty(Eval("Content"), ""))), false, " ")), 280, "...")), "", "")%>
<%-- Relevance, URL, Creattion --%>
<%-- Relevance --%>
%" style="width: 50px; border: solid 1px #aaaaaa; margin-top: 7px; margin-right: 6px; float: left; color: #0000ff; font-size: 2pt; line-height: 4px; height: 4px;">
        <%-- URL --%>
        <span style="color: #008000">
            <%# SearchHighlight(SearchResultUrl(true),"<strong>","</strong>")%>
        </span>
        <%-- Creation --%>
        <span style="color: #888888; font-size: 9pt">
            <%# GetDateTimeString(Helpers.ValidationHelper.GetDateTime(Eval("Created"), DateTimeHelper.ZERO_TIME), true) %>
        </span>
    </div>
</div>
0 votesVote for this answer Mark as a Correct answer

Sofia Khatoon answered on March 2, 2017 17:38 (last edited on March 2, 2017 17:38)

I modified the transform as below and now it has started working. Thanks Zach and Brenden for your timely help today. Greatly appreciated.

<div style="margin-bottom: 30px;">
    <%-- Search result title --%>
    <div>
        <a style="font-weight: bold" href='<%# SearchResultUrl(true) %>'>
            <%#SearchHighlight(HTMLHelper.HTMLEncode(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(DataHelper.GetNotEmpty(Eval("Title"), "/"))), "<span style='font-weight:bold;'>", "</span>")%>
        </a>
    </div>
    <%-- Search result content --%>
    <div style="margin-top: 5px; width: 590px;">
        <%#SearchHighlight(HTMLHelper.HTMLEncode(TextHelper.LimitLength(HttpUtility.HtmlDecode(HTMLHelper.StripTags(CMS.ExtendedControls.ControlsHelper.RemoveDynamicControls(GetSearchedContent(DataHelper.GetNotEmpty(Eval("Content"), ""))), false, " ")), 280, "...")), "<span style='background-color: #FEFF8F'>", "</span>")%><br />
    </div>
    <%-- Relevance, URL, Creattion --%>
    <div style="margin-top: 5px;">
        <%-- Relevance --%>
        <div title="Relevance: <%# Convert.ToInt32(CMS.Helpers.ValidationHelper.GetDouble(Eval("Score"),0.0)*100)%>%"
            style="width: 50px; border: solid 1px #aaaaaa; margin-top: 7px; margin-right: 6px; float: left; color: #0000ff; font-size: 2pt; line-height: 4px; height: 4px;">
            <div style='<%# "background-color:#a7d3a7;width:"+ Convert.ToString(Convert.ToInt32((CMS.Helpers.ValidationHelper.GetDouble(Eval("Score"),0.0)/2)*100))  + "px;height:4px;line-height: 4px;"%>'>
            </div>
        </div>
        <%-- URL --%>
        <span style="color: #008000">
            <%# SearchHighlight(SearchResultUrl(true),"<strong>","</strong>")%>
        </span>
        <%-- Creation --%>
        <span style="color: #888888; font-size: 9pt">
            <%# GetDateTimeString(CMS.Helpers.ValidationHelper.GetDateTime(Eval("Created"), DateTimeHelper.ZERO_TIME), true) %>
        </span>
    </div>
</div>
0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.