toddams / RazorLight

Template engine based on Microsoft's Razor parsing engine for .NET Core
Apache License 2.0
1.5k stars 259 forks source link

Unable to use Linq extension methods #523

Closed Fosol closed 1 year ago

Fosol commented 1 year ago

Describe the bug When I attempt to compile and render a string template it throws an error.

TNO.Services.Notification.NotificationManager: Error: Failed to handle message

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.Collections.Generic.List' does not contain a definition for 'FirstOrDefault'

To Reproduce Create a template that includes a Linq statement and a FirstOrDefault() extension method call.

Expected behavior I would expect as long as I have the @using System.Linq; statement in the template it should work correctly.

Information (please complete the following information):

Fosol commented 1 year ago

To resolve this it requires setting the @model or providing the engine additional type information so that it can use extension methods.