Constructor on type '###' not found
.net, c#, reflection
Solution
Works fine in .NET 4.5, and even 2.0
using System;
class SmaSeries
{
public SmaSeries(ISeries<decimal> parent, int periods,
TierKind? runOnTier = null) { }
static void Main()
{
object[] args = new object[]
{
new DecimalSeries(),
20,
new Nullable<TierKind>(TierKind.Client)
};
object obj = Activator.CreateInstance(typeof(SmaSeries), args);
}
}
enum TierKind { Client }
interface ISeries<T> { }
class DecimalSeries : ISeries<decimal> { }
I think perhaps: is your constructor or one of the types maybe not public?
Problem
I have a type that accepts these parameters: ``` public SmaSeries(ISeries<decimal> parent, int periods, TierKind? runOnTier = null) ``` I am trying to create an instance of this type using Activator.CreateInstance (the overload that accepts type and args) by passing object[] in the args parameter: ``` new object[] { new DecimalSeries(), 20, new Nullable<TierKind>(TierKind.Client) } //DecimalSeries implements ISeries<decimal> ``` Getting back Constructor on type 'SmaSeries' not found. Is there a way to fix the args so the activator finds the constructor? Thanks.