I have a strange issue. I've a method that expects an IEnumerable
of dynamic
that later I have to iterate to do some things.
The code that invokes the method is this:
GuardarControlCristalesPedidos(
items.Select(o => new {o.Id, o.CantidadRecibida, o.Cerrado}));
This method is coded as
public static void GuardarControlCristalesPedidos(IEnumerable itemsAGuardar)
{
var session = FactoryProvider.GetCurrentSession();
using (var t = session.BeginTransaction())
{
foreach (dynamic item in itemsAGuardar)
{
var cItem = session.Load<PedidoItem>(item.Id);
cItem.CantidadRecibida = item.CantidadRecibida;
cItem.Cerrado = item.Cerrado;
session.Save(cItem);
}
t.Commit();
}
}
Now, the problem I have is that the program fails throwing 'item.Id' produjo una excepción de tipo 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'
But strangely, when I access the dynamic
variable with the debugger it seems to be fine (the IDE displays the members fine, but fails when I try to access item.Id
What is happening here?