I'm trying to call a method in an aspx.cs but getting an InvalidOperationException
with message
Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.
My code is:
protected void BuildSurface(int newValue)
{
IEnumerable<dynamic> models = InitializeConfigurationForWorkflow(newValue);
List<Panel> panelList = new List<Panel>();
foreach (dynamic workflowConfiguration in models)
{
Type dynamicType = workflowConfiguration.GetType();
if (dynamicType.IsGenericType)
{
Type genericDynamicType = dynamicType.GetGenericTypeDefinition();
string methodName = null;
if (genericDynamicType.In(typeof(List<>), typeof(IEnumerable<>), typeof(IList<>)))
methodName = "GenerateListPanel";
else if (genericDynamicType == typeof(Dictionary<,>))
methodName = "GenerateDictionaryPanel";
if (methodName.IsNullOrEmpty()) continue;
Type[] listType = genericDynamicType.GetGenericArguments();
MethodInfo method = typeof(_admin_WorkflowConfiguration)
.GetMethods()
.Where(w => w.Name.Equals(methodName))
.First();
MethodInfo generic = method.MakeGenericMethod(listType);
panelList.Add(generic.Invoke(this, workflowConfiguration})); // here the error appears
}
}
}
my methods that will be called look like this one:
public Panel GenerateListPanel<T>(IEnumerable<T> workflowConfiguration)
{
Panel panel = new Panel();
return panel;
}
The dynamic-value is a json that gets deserialized to either Dictionary or List.
Any idea what I'm doing wrong?