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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:05:57+00:00 2026-05-28T11:05:57+00:00

I have am creating an Instance dynamically using Activator.CreateInstance. However, it is saying object

  • 0

I have am creating an Instance dynamically using Activator.CreateInstance. However, it is saying object cannot be null on every attempt. Pasting the code below. Am I doing anything wrong?

Is there any problem if

Activator.CreateInstance

replaces the conventional switch/case statements for determining the object type in the run-time? Thanks.

public abstract  class Base
{
    public abstract void Func();

}
public  class  Derived:Base
{
    public override void Func()
    {
        MessageBox.Show("Derived First");
    }
}

public class Derived2 : Base
{
    public override void Func()
    {
        MessageBox.Show("Derived Second");
    }
}

private void button1_Click(object sender, EventArgs e)
{
    // I was trying to make use of the overladed version 
    // where it takes the Type as parameter.
    BaseClass report = 
       (BaseClass) Activator.CreateInstance(Type.GetType("Derived")); 
    report.Func();
}
  • 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-28T11:05:58+00:00Added an answer on May 28, 2026 at 11:05 am

    From the documentation of the typeName parameter of Type.GetType:

    The assembly-qualified name of the type to get. See
    AssemblyQualifiedName. If the type is in the currently executing
    assembly or in Mscorlib.dll, it is sufficient to supply the type name
    qualified by its namespace.

    This means that you need to (at least) pass the namespace as well:

    BaseClass report = (BaseClass) Activator.CreateInstance(Type.GetType("YourNamespace.Derived")); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have some code using a System.Transactions.TransactionScope , that creating a new instance of
If I have to choose between static method and creating an instance and use
I have a problem related to creating an instance of a WCF ServiceHost withing
I have a 3rd party DLL that needs to be loaded dynamically using LoadLibrary()
After weeks of using Prism I have been through every kind of navigation methods.
I have a page that is creating dynamically created rows in a table with
I have a program that I am creating that creates task inputs dynamically. My
Im doing some test creating an instance of HTMLDocument this way: object[] pageText =
I have been creating a website with Ruby on Rails, and will be hosting

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.