RazorLight icon indicating copy to clipboard operation
RazorLight copied to clipboard

TemplateCompilationException: Cannot use a lambda expression - .Net Core 2.0

Open rsbavaresco opened this issue 9 years ago • 1 comments

For note,

This following Template which contains Lambda Expression, throws TemplateCompilationException in RazorLight version 2.0.0-alpha3 at method CompileRenderAsync.

Template:

@(@Model.Items?.Sum(p => p?.Quantity)) 

Exception:

RazorLight.TemplateCompilationException: 'Failed to compile generated Razor template:
- (0:24) Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.

Solved by declaring explicit Model Type in Template, making sure the Template is not Rendered as Dynamic.

@model MyProject.MyModel

Thanks

rsbavaresco avatar Oct 03 '17 18:10 rsbavaresco

I have this problem.

But my model is dynamic. i can not do the same solution

penihel avatar Feb 11 '19 00:02 penihel