vendredi 13 mars 2020

Constructor on type (...) not found when that type HAS a constructor

I am trying to find all classes with the custom attribute "ToolTestAttribute" and instantiate an instance of that class. When the code tries to run the constructor it is reporting that the constructor type is not found.

My class I am trying to start looks like this:

    public AllComponentsConstrained(ITool toolFile) 
    {
        tool = toolFile;
    }

My code that finds the classes with the attribute I need looks like this:

        List<object> StartTests(Assembly assem, ITool tool)
    {
        List<object> result = new List<object>();
        foreach (Type type in assem.GetTypes())
        {
            if (type.GetCustomAttributes(typeof(ToolTestAttribute), true).Length > 0)
            {
                List<ITool> args = new List<ITool>();
                args.Add(tool);
                result.Add(Activator.CreateInstance(type, args));
            }
        }
        return result;
    }

ToolTestAttribute code:

using System;
using System.Reflection;

namespace Sharpline.SL24.ToolingAddIn.Attributes
{
[AttributeUsage(AttributeTargets.Class)]
class ToolTestAttribute : Attribute
{
    public string Target;
    public string Name;

        public ToolTestAttribute(string testTarget, string testName)
        {
            Target = testTarget;
            Name = testName;
        }

    }
}

My args list has a single element of the correct type. What could be wrong here?





Aucun commentaire:

Enregistrer un commentaire