question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MvcHelper Directive produces uncompilable code

See original GitHub issue

There is a test template with Generator: MvcHelper directive is this repository: https://github.com/RazorGenerator/RazorGenerator/blob/master/RazorGenerator.Core.Test/TestFiles/Input/MvcHelperTest.cshtml

There also is a generated file from this template with RazorGenerator v1 here: https://github.com/RazorGenerator/RazorGenerator/blob/master/RazorGenerator.Core.Test/TestFiles/Output_v1/MvcHelperTest.txt

We can see that in this file we have a static class with a static extension method, which is compilable and fine.

But in a generated file for RazorGenerator v2 or v3 we have nonstatic file with a static extension method: https://github.com/RazorGenerator/RazorGenerator/blob/master/RazorGenerator.Core.Test/TestFiles/Output_v2/MvcHelperTest.txt#L37

Unfourtunatedly this code can’t be compiled in C#: Error CS1106: Extension method must be defined in a non-generic static class

Static changed to nonstatic in v2 via this commit: https://github.com/RazorGenerator/RazorGenerator/commit/7052aaae4b580d0e5518a3fe1b85423d2448f094#diff-97f8c72576b159fc6053d5bfc84f6d9e

Can you fix it somehow? I can’t regenerate some files in my solution anymore with this new version of RazorGenerator 😦

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
daipluspluscommented, Dec 5, 2018

@timramone, I’m actively involved in maintaining this project after being added to the project team by @pranavkm a few weeks ago, and I’m currently working through other issues with RazorGenerator at present but I’ll take a look at this when I get a chance.

I note that ASP.NET Core dropped support for @helper syntax in Razor pages, so your question might be moot if you’re targeting the latest version of ASP.NET (not to say this isn’t a bug, of course).

0reactions
pranavkmcommented, Dec 7, 2018

But it definitedly breaks backward compatibility, doesn’t it?

Unfortunately the breaking change was in MVC 4. All that RazorGenerator (primarily) does is provide a way to use MVC’s runtime capabilities at build time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is proper alternative to @helper directive in ASP.NET ...
1 Answer 1 · Create traditional custom HTML MVC Helpers (take note return type has changed in ASP.NET 5) · Create custom taghelpers...
Read more >
Tag Helpers in ASP.NET Core
Tag Helpers are authored in C#, and they target HTML elements based ... The @addTagHelper directive makes Tag Helpers available to the view....
Read more >
Discussion: bringing back @helper for views · Issue #5110
In porting some existing applications (from ASP.NET MVC 5), we're seeing immense amounts of pain with views that use @helper today.
Read more >
What Happened To @Helpers In ASP.NET Core?
A Helper in pre-ASP.NET Core Razor is a reusable snippet of Razor syntax exposed as a method, intended for rendering HTML to the...
Read more >
HTML Helpers in ASP.Net MVC
Generates Html controls based on data type of specified model property e.g. textbox for string property, numeric field for int, double or other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found