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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:02:14+00:00 2026-05-26T15:02:14+00:00

I have a public class with 2 constructors: The default (without parameters), which is

  • 0

I have a public class with 2 constructors: The default (without parameters), which is internal, and a different one, which is public.
The default constructor calls the other one with some default values.

I call the internal constructor using reflection, so it’s not used anywhere in the assembly statically (only by reflection).

When I make the reflection call, I’m getting:

System.MissingMethodException
    Message=No parameterless constructor defined for this object.

I know of two workarounds:

  1. Make the constructor public (but I don’t want the users of this assembly to use it).
  2. Call the constructor from some public method (I have many classes like this one, so I don’t want to write a lot of this ugly useless code).

Any better solutions to this problem?

It’s worth mentioning that if the default constructor is public, I don’t get that exception.

Thanks,

Boaz.

  • 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-26T15:02:15+00:00Added an answer on May 26, 2026 at 3:02 pm

    The constructor is not removed, probably in the search of your constructor you should specify the flag BindingFlag.NonPublic.

        class xxx
        {
            private xxx() :
                this(10)
            {
            }
    
            public xxx(int value)
            {
                Console.WriteLine(value);
            }
        }
    
        static void Main(string[] args)
        {
            Activator.CreateInstance(typeof(xxx), true);
            Console.ReadLine();
        }
    

    Activator.CreateInstance have an overload with a boolean where you can specify if you want to call a non public constructor.

    public static Object CreateInstance(
        Type type,
        bool nonPublic
    )
    

    Activator.CreateInstance(type, true) will call the constructor both if it is public or private\internal\protected.

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

Sidebar

Related Questions

I have a class which has the following constructor public DelayCompositeDesigner(DelayComposite CompositeObject) { InitializeComponent();
I have a class ReportingComponent<T> , which has the constructor: public ReportingComponent(IQueryable<T> query) {}
I have a struct which takes 3 named parameters in to the constructor... public
Given I have a class with two constructors: public class TestClass { ObjectOne o1;
I have a class with two constructors that look like this: public MyClass(SomeOtherClass source)
I have a generic class in C# with 2 constructors: public Houses(params T[] InitialiseElements)
I have a varargs constructor like this : public class Sentence { public String[]
I have a constructor question for C#. I have this class: public partial class
I have a class with two ctors. One parameterless and one with parameters. Unity
Create a class with a default constructor (one that takes no arguments) that prints

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.