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 8960053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:35:11+00:00 2026-06-15T15:35:11+00:00

I have a very simple generic constructor method: public T Instance<T, TT>(TT parms) where

  • 0

I have a very simple generic constructor method:

public T Instance<T, TT>(TT parms) where T : class
{
    return (T)Activator.CreateInstance(typeof(T), new[] { parms });
}

When I call the method like:

Instance<MyClass, string>("SomeStringValue").Customers.Where(x => x.Id == Id).Select(p => blah..blah...blah;

I get a ‘System.MissingMethodException: Constructor on type ‘MyClass’ not found.
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture…’

I have tried adding bindingflags etc. but without any luck.

I am basically trying to instantiate an object with arguments.
I can without any problems explicitly declare the object:

var myObj = new MyClass("SomeStringValue");

But I need to make use of my generic constructor.

Can anyone clarify what I am missing?

EDIT
A complete program (simplified).

public abstract class A 
{
    public T Instance<T, TT>(TT parms) where T : class
    {
       return (T)Activator.CreateInstance(typeof(T), new[] { parms });
    }
}

public class B 
{
    public B(string someValue)
    {
        var myValue = someValue;
    }
}

public class C
{
  public void DoStuff()
  {
     var x = Instance<B, string>("SomeStringValue");
  }
}

Is what I am trying to do.

  • 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-06-15T15:35:13+00:00Added an answer on June 15, 2026 at 3:35 pm

    The Activator<T>.CreateInstance() overload you’re trying to call expects a second argument of type Object[]. The new array you are creating is a TT[]. If TT were constrained to a class type, then a TT[] might satisfy the Object[] parameter. An unconstrained generic TT[], however, cannot be used as an Object[]. Once the compiler determines that the TT[] cannot be passed as an Object[], it then (because of the params specification on the second parameter of the overload), it checks whether the second parameter you’re passing qualifies as an Object. Because all arrays derive from Object, it will. The compiler will thus create a single-element array of type Object which holds the TT[] that you were trying to pass in. Since there is no constructor that expects an Object[], the call will fail.

    If you want to prevent this problem, create a new Object[] containing the appropriate parameters, instead of creating a new TT[]. That should solve your problem.

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

Sidebar

Related Questions

I have a very simple object models. public class Contact { public virtual int
I have a very simple question, how would you document with xmldoc a method
So basically what I have set up here is a very simple and generic
I created a very simple event publisher and it looks like this. public class
We have method that looks like this : public String getCommandString(Object...args) { return this.code
I have very simple piece of code. The goal is when i input four-digit
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have very simple window where I have 2 buttons - one for cancel,
I have a very simple table called Member , which consists of the following:
I have a very simple fxml file, with a checkbox: ... <AnchorPane id=AnchorPane xmlns:fx=http://javafx.com/fxml

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.