Templated Razor Delegates within a @section = '__razor_template_writer': a parameter or local variable cannot have the same name as a method type parameter #672
Description
I'm having problems creating templated razor delegates within a section of a page.
_Layout.chtml
@RenderSection("test", false)
_SubLayout.cshtml
@section test {
@ { Func<dynamic, object> f = @<span>@item</span>; }
}
Which gives me this error:
CS0412 '__razor_template_writer': a parameter or local variable cannot have the same name as a method type parameter
So I went to look at what gets generated, and this is it
Func<dynamic, Microsoft.AspNet.Mvc.Razor.HelperResult> e =
item => new Microsoft.AspNet.Mvc.Razor.HelperResult(async (__razor_template_writer) =>
{
BeginContext(2881, 6, true);
WriteLiteralTo(__razor_template_writer, "<span>");
EndContext();
BeginContext(2888, 4, false);
WriteTo(__razor_template_writer, item);
EndContext();
BeginContext(2893, 7, true);
WriteLiteralTo(__razor_template_writer, "</span>");
EndContext();
});
So the error makes sense, in the section there's already a method parameter called __razor_template_writer when a section is created, and now by creating a templated razor delegate, it tried to create another '__razor_template_write' parameter, hence the error.
I then copied the above code to my view just changed the method parameter name from __razor_template_writer
to __test
in the above function and called @e("this is a test")
. It works.
I tested the initial problem code in MVC5 and works fine, so my question is, is this a bug?
It smells like one. And also, is there a way around it?