RazorEngine.NetCore : The name 'PopWriter' does not exist in the current context

Viewed 310

I'm stuck in a issue with the RazorEngine.NetCore library. I'm using it inside a netstandard2.0 library, that is being used both by a .NET Core Application and also a .NET 4.7 application (FullFramework).

For some templates, ok, it worksfine. But for some templates, it starts to use some methods like PushWriter and PopWriter inside the generated class when compiling the template.

IRazorEngineService _razorService = RazorEngineService.Create(new TemplateServiceConfiguration()
        {
            ReferenceResolver = new MyIReferenceResolver(), 
            Debug = true,
            EncodedStringFactory = new RawStringFactory(),
            BaseTemplateType = typeof(CustomTemplateBase<>)
        });

Then I'm adding the template from the Library (a cshtml view) and the type that is being used as a model:

_razorService.AddTemplate(name, ReadTemplate(template));
_razorService.Compile(name, type);

But when it hits the Compile method I got this error:

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: (111, 16) The name 'PushWriter' does not exist in the current context
     - error: (115, 258) The name 'PopWriter' does not exist in the current context
     - error: (131, 16) The name 'PushWriter' does not exist in the current context
     - error: (138, 41) The name 'PopWriter' does not exist in the current context
     - error: (150, 16) The name 'PushWriter' does not exist in the current context
     - error: (152, 277) The name 'PopWriter' does not exist in the current context
     - error: (200, 16) The name 'PushWriter' does not exist in the current context
     - error: (202, 261) The name 'PopWriter' does not exist in the current context
     - error: (413, 16) The name 'PushWriter' does not exist in the current context
     - error: (415, 224) The name 'PopWriter' does not exist in the current context
     - error: (468, 16) The name 'PushWriter' does not exist in the current context
     - error: (470, 277) The name 'PopWriter' does not exist in the current context
     - warning: (102, 8) The variable 'sector' is assigned but its value is never used
Temporary files of the compilation can be found in (please delete the folder): C:\[folder-structure-hidden]\RazorEngine_kg4royrl.trc
The template we tried to compile is: 

I added Microsoft.AspNetCore.Mvc and Microsoft.AspNetCore.Mvc.Razor to project references and also to the MyIReferenceResolver too, but no success.

Part of the code generated that I can see inside the exception that is generated by the Roslyn is something like this:

BeginWriteAttribute("style", " style=\"", 8783, "\"", 8878, 3);
            WriteAttributeValue("", 8791, "min-width:100%;", 8791, 15, true);
            WriteAttributeValue(" ", 8806, new Microsoft.AspNetCore.Mvc.Razor.HelperResult(async(__razor_attribute_value_writer) => {
                PushWriter(__razor_attribute_value_writer);
                                                                                                                                                                                                if (f.Something) {WriteLiteral("border-right: 1px solid #dddddd;");
                                                                                                                                                                                                                                                                    }PopWriter();
            }
            ), 8807, 70, false);

Anyone has experienced this before?

Thank you!

0 Answers
Related