I am trying to use Activator.CreateInstance()
to instantiate an array that has fields of a dynamic type (I get the type that I must use for array fields during the runtime as Type arrayType = arrayFieldType.MakeArrayType()
).
singleSet.ZaznamyObjektu = Activator.CreateInstance(arrayType, new object[] { rowCount });
(rowCount
is an integer.) I have chosen this approach according to How do I create a C# array using Reflection and only type info? but it keeps giving me RuntimeBinderException:
Cannot implicitly convert type 'object' to 'PodperneZarizeniTypeZaznamObjektu[]'. An explicit conversion exists (are you missing a cast?)
But I do not know how to make cast or conversion when I cannot use the exact name of the type. I have also tried to use Array.CreateInstance()
but it was giving me similar exception:
Cannot implicitly convert type 'System.Array' to 'PodperneZarizeniTypeZaznamObjektu[]'. An explicit conversion exists (are you missing a cast?)