toddams/RazorLight

Unable to use Linq extension methods

Fosol opened this issue · 1 comments

Fosol commented

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<TNO.API.Areas.Services.Models.Content.ContentTonePoolModel>' 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):

  • OS: Any. I'm currently testing on Windows 11, but I also am getting the error in a docker container dotnet/skd:7.0.
  • Platform .NET 7
  • RazorLight version 2.3.1
  • Are you using the OFFICIAL RazorLight package? yes
  • vscode
Fosol commented

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