Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3605198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:05:38+00:00 2026-05-18T21:05:38+00:00

I am trying to come up with a method factory that looks inside config

  • 0

I am trying to come up with a method factory that looks inside config to get the full name of the type to instantiate and creates that object type dynamically.

Here is my Type and the Interface:

public interface IComponent<T> 
{
    IEnumerable<T> DataSource {get; set;}

    void PerformTask(object executionContext);

}

namespace MyCompany.Components 
{
    public class ConcreteComponent1<T> : IComponent<T> 
    {

        private IEnumerable<Contact> contactSource = null;

        internal ConcreteComponent1() {}

        public void PerformTask(object executionContext) 
        {
            this.contactSource = GetSource(executionContext);

            foreach(var result in this.contactSource) 
            {
                result.Execute(executionContext); 
            }
        }

        public IEnumerable<T> DataSource 
        {
            get { return this.contactSource as IEnumerable<T>; }
            set { this.contactSource = (IContactSource)value; }
        }
    }
}

Factory, resides in the same assembly:

//Factory - Same assembly
public static class ComponentFactory<T> 
{
    public static IComponent<T> CreateComponent() 
    {
        var assembly = Assembly.GetExecutingAssembly();
        object o = assembly.CreateInstance("MyCompany.Components.ConcreteComponent1"); //o is null...

        var objectHandle = Activator.CreateInstance(Assembly.GetAssembl(typeof(ComponentFactory<T>)).GetName().FullName, "MyCompany.Components.ConcreteComponent1"); //throws Could not load type from assembly exception.                     
        return o as IComponent<T>;
    }
}

So in first case the o is always null.

In the second case when using the Activator class, it throws Type could not be loaded from assembly “MyAssembly”. No inner exception. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:05:39+00:00Added an answer on May 18, 2026 at 9:05 pm

    First of all, actual name of your type is:

    MyCompany.Components.ConcreteComponent1`1
    

    It can’t be instantiated because you have to specify type parameters:

    public static class ComponentFactory<T>
    {
        public static IComponent<T> CreateComponent()
        {
            Type generic = Type.GetType("MyCompany.Components.ConcreteComponent1`1");
            Type concrete = generic.MakeGenericType(typeof(T));
            var objectHandle = Activator.CreateInstance(
               concrete,
               BindingFlags.NonPublic | BindingFlags.Instance,
               null,
               null, //here can come ctor params
               null); 
            return objectHandle as IComponent<T>;
        }
    }
    

    this will work with internal constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to come up with a method, that given a day of
I am trying to come up with a method of extracting 4 characters that
I am trying to come up with a design for a method that takes
I am trying to come up with a method that takes an integer and
I am trying to come up with a C# method that will be able
I'm trying to come up with a javascript/jquery method that will allow me to
I'm trying to come up with a method which will measure and return the
I'm trying to come up with an answer to two questions that didn't seem
I'm trying to come up with the largest possible group of friends that would
I'm trying come up with the best method of synchronizing particular rows of 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.