Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception : One or more section(s) have been ignored. Ignored section(s) #535

Open
sybaris opened this issue Nov 13, 2023 · 0 comments
Open

Comments

@sybaris
Copy link

sybaris commented Nov 13, 2023

Describe the bug
The following code throw an exception "System.InvalidOperationException: 'One or more section(s) have been ignored. Ignored section(s): 'data''"

To Reproduce

   internal class Program
    {
        const string LAYOUT = @"
    @{ if (Model.Count>0)
        {
            @RenderSection(""data"", required: false)
        }
    }
    @RenderBody()";
        
        const string PAGE = @"
@{
    Layout = ""_Layout.cshtml"";
}

@section data {
    <p>This will be rendered inside Layout</p>
}";


        static async Task Main(string[] args)
        {
            var engine = new RazorLightEngineBuilder()
                .UseEmbeddedResourcesProject(typeof(Program))
                .AddDynamicTemplates(new Dictionary<string, string>() { { "_Layout.cshtml", LAYOUT } })
                .SetOperatingAssembly(typeof(Program).Assembly)
                .UseMemoryCachingProvider()
                .Build();
            
            // This runs ok.
            string result1 = await engine.CompileRenderStringAsync("templateKey", PAGE, new List<string>() { "1" });
            Console.WriteLine(result1);
            // This raise an exception "System.InvalidOperationException: 'One or more section(s) have been ignored. Ignored section(s): 'data''"
            string result2 = await engine.CompileRenderStringAsync("templateKey", PAGE, new List<string>() );
            Console.WriteLine(result2);
        }
    }

Expected behavior
I expect to not have an exception.
Or I except to have a flag somewhere to override this check.

Information (please complete the following information):

  • RazorLight version 2.3.1
  • Visual Studio 2022
  • Dotnet 6.0
    Additional context
    Add any other context about the problem here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant