Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 03, 2012 02:09 PM by DriesM
Feb 28, 2012 03:20 PM|LINK
In my Razor files I use some custom Html Helpers like Html.MyHelper(Byval helper As HtmlHelper, optional byval text as string = "", optional byval image as string = ""). The helpers are located in a separate class library and are compiled into a CustomHtmlHelpers.dll
When I add one or more OPTIONAL parameters to a helper e.g.: Html.MyHelper(Byval helper As HtmlHelper, optional byval text as string, optional byval image as string,
optional byval tag as string = "") that is used in a Razor file and compile it, my application always breaks with the message "method not found MyHelper... . Whatever I do I always have te go over every Razor file that uses this helper and
manually change something and resave the Razor file before it again finds the helper. I would think this is normal behavior when i would change a helper and add a REQUIRED parameter but not an Optional parameter right?
The same error also happens when I rename a parameter, not changing the type or default value, just renaming it like this Html.MyHelper(Byval helper As HtmlHelper, optional byval text as string = "",
optional byval img as string = "") results in a "Method not found error" and again have to go over al my Razor files that use this helper. I' m not using named parameters so i would think after compiling my helpers, Razor would just pick up
the changed helper, because from a Razor point of view nothing has changed in the helper method.
Has someone else experienced this behavior and maybe found a solution?
Feb 28, 2012 03:25 PM|LINK
if you change the signatues of methods in dll's, you need to do a rebuild.
Feb 28, 2012 03:34 PM|LINK
Thanks for your reply.
Of course after I change a optional parameter I rebuild(recompile) the class library and the whole application as matter of fact.
That's what I find strange, I rebuild after changing the parameter name or adding an optional parameter, but Razor does not find the changed method and throws an error "method not found", but like i said, from a Razor point of view nothing has changed, it was
an optional parameter I added not a required one or I changed a parametername but not the type or value and I do not use named parameters when using the Helper method in the razor files.
Feb 28, 2012 07:41 PM|LINK
After some debugging the problem is definitely Razor and method signatures, for some reason the Razor views do no react to changes on optional parameters default value or an error is thrown when parameter names are changed or optional parameters are added.
The changes to parameters are only picked up after manually changing the Razor view. Is this a caching problem?? Does anyone have a clue?
Mar 03, 2012 11:57 AM|LINK
There is nothing special with Razor. Razor is compiled int an assembly.
It will helpfull if you see which assemblies razor view class is referencing during compilation. This
trick will provide you this information.
Mar 03, 2012 02:09 PM|LINK
Finally solved it.
In the web.config file under the section system.web > compilation the attribute optimizeCompilations was set to true so method signature changes and changes in default values of optional parameters where not compiled. Set it to false and solved my issue.