Compiler Error Message: CS1963: An expression tree may not contain a dynamic operation

Topics: Customizing Orchard, Troubleshooting
Mar 20, 2013 at 8:22 PM
Edited Mar 20, 2013 at 8:36 PM
I don't understand why I am getting this error when Orchard try to use a dynamic model (from Nwazet.Commerce).
This was working recently.... and I have apparently changed nothing. Is it possible that the compiled code running ok was in cache and has been deleted.

I am using the Clayless version ?

beg of the model
@using Nwazet.Commerce.Models
    var method = (SizeBasedShippingMethodPart)Model.ShippingMethod;
    var shippingAreas = (IEnumerable<ShippingArea>)Model.ShippingAreas;
    var includedAreas = new HashSet<string>((method.IncludedShippingAreas ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
    var excludedAreas = new HashSet<string>((method.ExcludedShippingAreas ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
    <label class="sub" for="@Html.IdFor(m => m.Name)">@T("Method Name")</label><br />
    @Html.TextBox("Name", method.Name, new { @class = "text" })<br />
    <span class="hint">@T("The technical name of the shipping method (this is different from the title, which is the method's friendly name that will be displayed to end-users).")</span><br/>
    <label class="sub" for="@Html.IdFor(m => m.ShippingCompany)">@T("Shipping Company")</label><br />
    @Html.TextBox("ShippingCompany", method.ShippingCompany, new { @class = "text" })<br />
    <label class="sub" for="@Html.IdFor(m => m.Price)">@T("Price")</label><br />
    @Html.TextBox("Price", method.Price, new { @class = "text" })<br />
    <label class="sub" for="@Html.IdFor(m => m.Size)">@T("Size")</label><br />
    @Html.TextBox("Size", method.Size, new { @class = "text" })<br />
Mar 20, 2013 at 8:48 PM
Strange, I have removed the @html.IdFor and it works, but I am sure it was working with them previously.
Mar 20, 2013 at 9:10 PM
This is because you can't use a dynamic model object with the lambda-based helpers.
Mar 20, 2013 at 10:45 PM
Edited Mar 20, 2013 at 10:48 PM
Yes, thanks this I have catched, but the question was more: why was it running before ?
Is it the removing of Clay ?
Mar 20, 2013 at 11:39 PM
It wasn't. Seriously, that's impossible. You must have had a strongly-typed model before, and have switched or added a cast to dynamic.