Razorlight: ExpandoObject as model type throws RuntimeBinderException

Created on 10 Apr 2017  路  1Comment  路  Source: toddams/RazorLight

Hi,

This code throws RuntimeBinderException (Additional information: 'System.Dynamic.ExpandoObject' does not contain a definition for 'price')

var engine = EngineFactory.CreatePhysical("D:\\views");

var obj = new ExpandoObject();
dynamic dynamicObj = obj;
dynamicObj.price = 30;

engine.Parse("test.cshtml", obj);

I believe problem occurs because of this line:
https://github.com/toddams/RazorLight/blob/master/src/RazorLight/ModelTypeInfo.cs#L42

Seems that ToExpando() doesn't handle ExpandoObject parameter correctly, as it returns new empty ExpandoObject as a result.

Thanks!

bug

Most helpful comment

That's right, ToExpando() method expects to receive anonymous object and convert it to ExpandoObject.
I will add additional check, thanks

>All comments

That's right, ToExpando() method expects to receive anonymous object and convert it to ExpandoObject.
I will add additional check, thanks

Was this page helpful?
0 / 5 - 0 ratings