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.

Unable to migrate from RazorEngine: "error: (19, 18) The name 'inherits' does not exist in the current context"

See original GitHub issue

I’m currently trying to migrate away from the old RazorEngine v3.10.0 to RazorEngineCore v2.2.6. I changed the package and my project compiles. After getting a message related to the @model directive, I found out it is not supported in the Core version, and that, if one wants to have intellisense, one has to add an @inherits tag.

https://github.com/adoconnection/RazorEngineCore/wiki/Switch-from-RazorEngine-cshtml-templates#template

However, when I add that in place of the old @model, I get an exception:

 RazorEngine.Templating.TemplateCompilationException : Errors while compiling a Template.
    Please try the following to solve the situation:
      * If the problem is about missing/invalid references or multiple defines either try to load 
        the missing references manually (in the compiling appdomain!) or
        Specify your references manually by providing your own IReferenceResolver implementation.
        See https://antaris.github.io/RazorEngine/ReferenceResolver.html for details.
        Currently all references have to be available as files!
      * If you get 'class' does not contain a definition for 'member': 
            try another modelType (for example 'null' to make the model dynamic).
            NOTE: You CANNOT use typeof(dynamic) to make the model dynamic!
        Or try to use static instead of anonymous/dynamic types.
    More details about the error:
     - error: (19, 18) The name 'inherits' does not exist in the current context

I tried both:

  • @inherits RazorEngineCore.RazorEngineTemplateBase<MyModel> (which actually gives me red squiggly lines in the editor) as well as
  • @inherits RazorEngine.Templating.TemplateBase<MyModel>

What am I missing?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
julealgoncommented, Nov 29, 2021

@julealgon Any chance you figured out your issue here? I know this issue relates to a different library, but I am running into the exact same issue. My ‘@inherits’ or ‘@model’ isnt working when I upgraded to RazorEngine.NetCore. I’ve been pretty unsuccessful finding a solution so far, and your the first person I’ve seen with the same issue. Any help is appreciated. Thank You!

@neilgaietto when I was discussing this topic here, we were trying to leverage RazorEngine.NetCore due to its higher apparent level of compatibility with the old native libraries. However, we never got it to work 100% and we’ve since actually made the jump and migrated to RazorEngineCore while making the necessary adjustments to our previous logic. The decision to go with RazorEngineCore was made while we were still in the initial steps of this process, so we never managed to get a full solution working with RazorEngine.NetCore.

For that reason, I probably won’t be able to help you with your issue. I’d recommend opening an issue in the other repo and/or posting a question to StackOverflow and see if you get any traction there.

1reaction
neilgaiettocommented, Nov 27, 2021

@julealgon Any chance you figured out your issue here? I know this issue relates to a different library, but I am running into the exact same issue. My ‘@inherits’ or ‘@model’ isnt working when I upgraded to RazorEngine.NetCore. I’ve been pretty unsuccessful finding a solution so far, and your the first person I’ve seen with the same issue. Any help is appreciated. Thank You!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - RazorEngine throws 'the name model does not exist in ...
RazorEngine is a custom library built on top of Microsoft's Razor view engine. ... The name 'model' does not exist in the current...
Read more >
Custom User Management in ASP.NET Core MVC ...
We will build a small yet practical implementation of Custom User Management in ASP.NET Core MVC with Identity. This will cover most of...
Read more >
Error CS0103 The name 'ViewBag' does not exist in the ...
In this case I had a legacy application that I was updating to a more recent platform and this error cropped up quite...
Read more >
NancyFX Migration from 0.9 to 0.10
As you try to build the project after upgrade, it would fail because of ... 18) The name 'Url' does not exist in...
Read more >
Razor syntax reference for ASP.NET Core
Razor is a markup syntax for embedding .NET based code into webpages. The Razor syntax consists of Razor markup, C#, and HTML. Files...
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