I am getting an InvalidOperationException with the message:
"Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true."
The following is the relevant part of the code:
// Gets the entity type of the table to update.
Type entityType = Jobs.GetType(syncSettings.TableToUpdate);
// Creates a generic list with the same type to hold the records to update.
Type listType = typeof(List<>).MakeGenericType(entityType);
object recordsToUpdate = Activator.CreateInstance(listType);
// Fills the list recordsToUpdate...
// A few lines below, I try to call the extension method ElementAt:
MethodInfo elementAtMethod = typeof(Enumerable).GetMethod("ElementAt", BindingFlags.Static | BindingFlags.Public);
elementAtMethod.MakeGenericMethod(entityType);
object record = elementAtMethod.Invoke(
recordsToUpdate,
new object[] { recordsToUpdate, recordIndex });
In my last action, the exception mentioned above is thrown. What am I doing wrong? What does this error mean?
I have been investigating and it seems that the method parameter type T is still generic. That's why ContainsGenericParameters is true. How do I set the parameter to the entityType?