Removal of extensial method Url.PageUrl is causing an exception

Vote:
 

I have a extension method "PageUrl" that is overriding the PageUrl method in EPiServer.Web.Mvc.Html.UrlExtensions

public static IHtmlString PageUrl(this UrlHelper urlHelper, string classicUrl)

When I remove my extension method then I get an exception that my method is not found. But if I remove the usage of it on the views where it is used, compile the code and then reenter the usage of it and compile then no exception is triggered. This method works locally but not if I want to deploy the code to the live site...

Is there a way to let the "system" know that it should use PageUrl that is in EPiServer.Web.Mvc.Html.UrlExtensions instead of my removed method?

I have also tried to move the extension method to another class but then I get this message when hovering over the PageUrl method in the views where it is used:

"The call is ambiguous between the following methods or properties: 'EPiServer.Web.Mvc.Html.UrlExtensions.PageUrl(System.Web.Mvc.UrlHelper, string)' and MyEPiApplication.Helpers.UrlHelpers.PageUrl(System.Web.Mvc.UrlHelper, string)'".

#266617
Nov 12, 2021 9:30
Vote:
 

How to let the system know?

1) Add a `@using` statement to the top of your view file

2) Add the namespace containing the extension method to the web.config file inside the view folder

Example: 

#266705
Nov 14, 2021 19:33
Vote:
 

Thanks for your answer!

I solved it by:

  1. Exchanged the usage of Url.PageUrl(page.LinkURL) with EPiServer.Web.Mvc.Html.UrlExtensions.PageUrl(Url, page.LinkURL).
  2. Removed my extension method.
  3. Pushed the code to all environments.
  4. Changed back from EPiServer.Web.Mvc.Html.UrlExtensions.PageUrl(Url, page.LinkURL)to Url.PageUrl(page.LinkURL).
  5. Pushed the code to all environments.
#266869
Nov 17, 2021 11:01
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.