Error: remove not available for dynamic objects
base on Microsoft's docs, The Remove
method of IList<T>
accepts a parameter with the type of T
:
ICollection<T>.Remove(T)
In your example, T
is an ExpandoObject
, so it means in the Remove
method you should pass a parameter with the type of ExpandoObject
but you didn't and you are passing a parameter with the type of dynamic
. Therefore you facing this error
for resolving this you have two way:
1) Use explicit type instead of var
:
ExpandoObject result = ...
2) cast the result
when you are passing it to Remove
:
Data.Remove((ExpandoObject) result)
I think with doing one of these ways, your problem will resolve. good luck.