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.

CompileRenderAsync fails to render very long htmls

See original GitHub issue

Describe the bug I’m using Razorlight to render HTML from the server. I have a view with 2 partial views inside. One partial view renders static HTML, while the other iterates through a collection and renders html for every item in it.

When the collection has many items (in my tests, 10 or more), the string returned from CompileRenderAsync doesn’t include the second partial view that iterates through the collection.

It doesn’t throws any exception, it just renders everything but the partial view that depends on the collection.

To Reproduce Steps to reproduce the behavior:

I have implemented this code, following the example on GitHub:

var engine = new RazorLightEngineBuilder()
          .UseFilesystemProject("physical-path-to-Views-folder")
          .UseMemoryCachingProvider()
          .Build();

var html = await engine.CompileRenderAsync("Report.cshtml", resultReport);

Report.cshtml has 2 partial views:

@inherits RazorLight.TemplatePage<MyAssembly.Data.Model.ResultReport>
@model MyAssembly.Data.Model.ResultReport

@{
     await IncludeAsync("Partial/_summary.cshtml", Model);
     await IncludeAsync("Partial/_riskReport.cshtml", Model);
}

_summary.cshtml shows static information from some properties of the model, while _riskReport.cshtml iterates through a collection of risks:

<div>
	@foreach (var risk in Model.Risks)
	{
	     <div class="@risk.Level">
		<div class="title-container"><h2 class="title">@risk.Title</h2><h3 class="level">@risk.Level</h3></div>
		<div>@Raw(risk.Description)</div>
	     </div>
	}
</div>

Expected behavior It should render html with a Summary Section (_summary.cshtml) and a list of Risks (_riskReport.cshtml). When the list of Risk has many items, it only renders the Summary Section.

Information (please complete the following information):

  • OS: Windows 7
  • Platform Net. Core 2.1
  • RazorLight version 2.0.0-beta1
  • Visual Studio version Visual Studio 2017

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
g0nPcommented, Jul 10, 2019

UPDATE:

The error mentioned above happens when I use the NuGet Package Razorlight. I have tried downloading the project and manually adding it to my Application and now it works like a charm. However I cannot go that way. I need it to be a NuGet package.

The difference I’ve noticed is that when using the NuGet package, the following code:

var engine = new RazorLightEngineBuilder()
          .UseFilesystemProject("physical-path-to-Views-folder")

has the method UseFilesystemProject with system in lower case. However when I manually add the project downloaded from GitHub, the method is UseFileSystemProject with System starting with capital letter.

Maybe an update is missing in the NuGet package?

EDIT 1:

The NuGet Package that is failing is called Razorlight and is the version 2.0.0-beta1 The code that works is the one I downloaded from the branch master as of today (7/10/2019)

EDIT 2:

It seems that the NuGet Package named Razorlight.Unofficial is the one using the current master branch and by using the latest version of that package (2.0.0-beta3) I was able to make the render work correctly.

Is there a plan to make this version “official”?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Looking for simplest option to render Razor cshtml pages ...
With the emerge of ASP.NET Core architecture, I am hoping that I can render Razor cshtml pages into a string without the need...
Read more >
RazorLight
The simplest scenario is to create a template from string. Each template must have a templateKey that is associated with it, so you...
Read more >
Timeout while rendering PDF
IronPDF's default rendering timeout is 60* seconds. Not setting a timeout, or having a render delay longer than the set timeout, will produce...
Read more >
Nreco.pdfgenerator asp.net core
IronPDF does not render HTML to PDF from a remote server. Rather, it spins up an instance of a real, standards-compliant web browser...
Read more >
How to: Render ASP.NET MVC Razor Views to Strings
Typically, Razor rendering in ASP.NET MVC is reserved purely for view rendering and generation of HTML output as part of an MVC request....
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