Just upgraded to .NET 2.0 beta 1.
It is working, compiling, etc. But in a couple of scenarios, my child HTML template just does not render. In the generated HTML there's just nothing there, also no errors.
E.g. this used to work in 1.1, not anymore in 2.0:
<tr style="@(rs.ActivityBookings == null || rs.ActivityBookings.Count == 0 ? "display:inherit" : "display:none")">
And when using a foreach, I now have to check if there are more than zero items. Without that check, again nothing rendered.
This is quite frustrating as this is trial and error, with no clue why this is not working. Am I doing something wrong?
Thanks for the reply @toddams
<div class="stops">
@{ await IncludeAsync("/Booking/StopContainer.cshtml", Model); }
</div>
StopContainer.cshtml is quite long. But it was working in .NET Core 1.1, but stopped working in .NET 2.0. It would just render <div class="stops"></div>
As soon as I stripped almost everything from StopContainer.cshtml, it would render something again.
But if I'd add something like the
foreach (var hb in rs.HotelBookings)
{
<h1>@hb.Title</h1>
}
HotelBookings is a collection. When HotelBookings has zero items, above HTML causes again the template to not render.
I had to change it to:
@if (rs.HotelBookings.Count > 0)
{
foreach (var hb in rs.HotelBookings)
{
<h1>@hb.Title</h1>
}
}
It is quite weird, but very annoying. The child template is quite long, and time consuming to analyze.
I've stopped at the point where rendering a certain property causes the template not to render.
By the way, no intellisense or debug warnings.
@toddams when I compile the child template directly, it works fine.
It seems to have something to do with the rendering of child templates.
I've also have trouble with child template.
Snippet from main template:
@foreach (var subscription in Model.Subscriptions)
{
<table class="outer" align="center" style="border-spacing: 0; font-family: arial, sans-serif; color: #333333; Margin: 0 auto; width: 100%; max-width: 600px;">
<tr>
<td class="one-column" style="padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0;">
<!-- Properties start -->
@{ await IncludeAsync("Parts.SubscriptionMail.Property.cshtml", subscription); }
<!-- Properties end -->
</td>
</tr>
Child template looks like this:
@using RazorLight
@using MyNamespace.TemplateModels.Subscription;
@using MyNamespace.TemplateModels;
@using DMyNamespace.TemplatePages;
@inherits SubscriptionTemplatePage<SubscriptionMailModel>
<table style="border-spacing: 0; font-family: arial, sans-serif; color: #333333; width: 100%;">
@foreach (var property in Model.Properties)
{
<tr>
<td class="contents" style="text-align: center; background-color: #fff; line-height: 24px; width: 100%; padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0;">
<a href="http://test.com/@property.Id" style="color: #007272; text-decoration: none;">
<img src="@property.MainImage" width="100%" height="auto" style="border-width: 0;" />
</a>
<p style="Margin: 0; font-size: 14px; Margin-bottom: 10px;"> </p>
<a class="size-24" href="http://test.com/@property.Id" style="color: #007272; text-decoration: none; font-size: 24px;">
@Helper.GetHeader(property)
</a><br />
@Helper.GetSubHeader(property)<br />
<strong>BOLIGTYPE:</strong>
<span class="gray" style="color: #666666;">
@Helper.GetObjectType(property)
</span><br />
@Raw(@Helper.GetPrice(property))
<p style="Margin: 0; font-size: 14px; Margin-bottom: 10px;"> </p>
<!--[if mso]>
<v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="http://test.com/@property.Id" arcsize="10%" stroke="f" fillcolor="#f87f00" style="height: 40px; v-text-anchor: middle; width: 200px;">
<w:anchorlock/>
<center>
<![endif]-->
<a class="btn-show-property" href="http://test.com/@property.Id" style="text-decoration: none; display: block; background-color: #f87f00; color: #ffffff; margin-top: 0; margin-bottom: 0; margin-right: auto; margin-left: auto; padding-top: 10px; padding-bottom: 10px; padding-right: 0; padding-left: 0; border-radius: 4px; font-size: 13px; font-weight: bold; width: 200px; font-family: arial, sans-serif;">Vis boligen</a>
<!--[if mso]>
</center>
</v:roundrect>
<![endif]-->
<p style="Margin: 0; font-size: 14px; Margin-bottom: 10px;"> </p>
</td>
</tr>
<tr>
<td class="row-padder" style="padding-top: 0; padding-bottom: 0; padding-right: 0; padding-left: 0; background-color: inherit;"> </td>
</tr>
}
</table>
This works when i have less then 5 objects in the subscription.Properties property. If i have more then 5 then it will stop rendering after <!-- Properties start -->. I don't get any exceptions but i get a broken template.
I found the bug, and that is a total disaster!)
Can't imagine how we've been using this for such a long time without facing this bug. It happens with big templates
Will prepare the next release, thank you for the very detailed description
@toddams When do you guess the nuget package will be released for this fix?
I also hit the same bug, child templates with a loop over a collection with the size more than 4 elements would not render at all.
@toddams: could you share details of the fix if you have one?
I am also seeing the same bug with child templates that contain loops over collections.
For me, @foreach (var int in new int[]{1, 2, 3, 4, 5, 6})
{
<p>@int</p>
} gives a blank template, but @foreach (var int in new int[]{1, 2, 3, 4, 5, 6}.Take(5))
{
<p>@int</p>
} displays fine. So it seems to be an issue with compiling an loop as soon as it goes over 5 elements
Do you have details on the fix?
I also have this issue. After playing around i saw that the problem (by me) only happens if i have a foreach loop within another foreach loop in a child view.
Can you please provide details of the fix?
Hi guys, i simply changed the file
src\RazorLight\Internal\Buffering\ViewBuffer.cs line21
public static readonly int ViewPageSize = 512; //(from 256)
my template works fine, then change back to 256 , it's broken again.
after set it to 512, works ; then provide a large mumber items to generate, fail again,
I 'm sure that the ViewPageSize is the point. sth generated bursted the "buffer".
so i temporary set it to a big enough number.
@toddams @favishG
@AstralRoad It worked! Thanks a lot.
@AstralRoad
There is an issue with flushing the buffer after each partial iteration. Increasing the ViewPageSize will just move the threshold, but issue could occur again on larger templates. I'm working on a fix
Do you have a time plan for when this bugfix will be released?
@toddams
I used RazorLight - 2.0.0-beta1 in my open source project SmartCode. I also found such a serious bug.
When can you post a new version to nuge to fix this bug?
Thank you very much!!!
Commit 0dbc5e1d174411530c3ab81db94dfc3444dd4a4d does not fix rendering issue. It is still occurring for large templates. The problem is caused by MemoryPoolViewBufferScope implementation (clearing/passing/returning the buffer).
I implemented workaround here https://github.com/wik8wz/RazorLight/commit/35f06da97ec7da7677379932397560410a44d04b
Any progress on this? We have already invested a great deal of time on a large project and then ran into this issue once our template got to big.
We went live with the fork which I created. Might switch back to original one when fixed.
We went live with the fork which I created. Might switch back to original one when fixed.
@wik8wz Can you open a PR from your fork with the fix?
@AstralRoad
There is an issue with flushing the buffer after each partial iteration. Increasing the ViewPageSize will just move the threshold, but issue could occur again on larger templates. I'm working on a fix
@toddams could you please release a nuget beta package with that fix?
I hit what sounds like this bug today.... sorry for the formatting.. could not quite get i right.. so the point in the bottom HTML is missing as the error is not visible....
Fairly simple main view:
@using Microsoft.EntityFrameworkCore.Internal
@using RazorLight
@using TMServerDb.Models.Core
@inherits RazorLight.TemplatePage
@{
DisableEncoding = true;
}
@{
await IncludeAsync("..\StandardItems\TournamentHeader.cshtml", (Model.Data as TMServerDb.Models.Core.MatchSet).Tournament);
}
@{
var ms = Model.Data as TMServerDb.Models.Core.MatchSet;
var grouped = ms.Matches.OrderBy(n => n.Number).ThenBy(p => p.Pitch.Name).GroupBy(s => s.PlannedStart);
foreach (IGrouping<DateTime, Match> grouping in grouped)
{
await IncludeAsync("..\\StandardItems\\MatchGrouping.cshtml", grouping);
<br/>
}
}
The nested view:
@using RazorLight
@using TMServerDb.Models.Core
@inherits RazorLight.TemplatePage
@Model.Key.Date.ToShortDateString()
@Model.Key.ToShortTimeString()
#
Pitch
Class
@{
foreach (Match match in Model.OrderBy(x => x.Pitch.Name))
{
@match.Number
@match.Pitch.Name
@match.Class.Name
}
}
When rendering, in my test, I have 30 odd groupings... but only a few make it to the pdf... intercepting the result from the rendering, explains why... notice the numerous ending of html and body tags...
<br>
| 01-06-2019 | 09:00 | |
|---|---|---|
| # | Pitch | Class |
| 1 | Pitch 1 | 4th Division |
| 2 | Pitch 2 | 1st Division |
| 3 | Pitch 3 | Women Division |
| 4 | Pitch 4 | Women Division |
| 5 | Pitch 5 | 2nd Division |
| 6 | Pitch 6 | 3th Division |
| 01-06-2019 | 09:30 | |
|---|---|---|
| # | Pitch | Class |
| 7 | Pitch 1 | 4th Division |
| 8 | Pitch 2 | 2nd Division |
| 9 | Pitch 3 | 1st Division |
| 10 | Pitch 4 | 2nd Division |
| 11 | Pitch 5 | 1st Division |
| 12 | Pitch 6 | 3th Division |
| 01-06-2019 | 10:00 | |
|---|---|---|
| # | Pitch | Class |
| 13 | Pitch 1 | 4th Division |
| 14 | Pitch 2 | Women Division |
| 15 | Pitch 3 | 2nd Division |
| 16 | Pitch 4 | 2nd Division |
| 17 | Pitch 5 | 1st Division |
| 18 | Pitch 6 | 3th Division |
| 01-06-2019 | 10:30 | |
|---|---|---|
| # | Pitch | Class |
| 19 | Pitch 1 | 4th Division |
| 20 | Pitch 2 | 1st Division |
| 21 | Pitch 3 | Women Division |
| 22 | Pitch 4 | 1st Division |
| 23 | Pitch 5 | 2nd Division |
| 24 | Pitch 6 | 3th Division |
Most helpful comment
@toddams When do you guess the nuget package will be released for this fix?