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

  • SEARCH
  • Home
  • 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 8246945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:40:37+00:00 2026-06-07T22:40:37+00:00

when i try to run the code below, I am getting Value cannot be

  • 0

when i try to run the code below, I am getting

“Value cannot be null. Parameter name: type”

error at runtime.

How to handle this exception and why my objectName is null here? I am expecting objectName to hold the value of local user account on my computer.

namespace Users
{
    class EnableDisableUsers
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Enter user account to be enabled or disabled");
            var user = Console.ReadLine();
            Console.WriteLine("Enter E to enable and D to disable the user account");
            string enableStr = Console.ReadLine();
            bool enable;
            var computer = ".";

            if (enableStr.Equals("E") || enableStr.Equals("e"))
            {
                enable = true;

                var objectName = "WinNT://" + computer + "/" + user + ",user"; 
                dynamic objUser = Activator.CreateInstance(Type.GetTypeFromProgID(objectName));
                objUser.AccountDisabled = false;
                objUser.SetInfo();
                Console.WriteLine(user + " Enabled = " + result.ToString());
                Console.ReadLine();
            }
            else if (enableStr.Equals("D") || enableStr.Equals("d"))
            {
                enable = false; 
                var objectName = "WinNT://" + computer + "/" + user + ",user";
                dynamic objUser = Activator.CreateInstance(Type.GetTypeFromProgID(objectName));
                objUser.AccountDisabled = true;
                objUser.SetInfo();
                Console.WriteLine(user + " Enabled = " + result.ToString());
                Console.ReadLine();    
            }
            else
            {
                Console.WriteLine("Operation for " + user + " failed ");
            }
        }
    }
}

Any help will be useful.

  • 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-07T22:40:40+00:00Added an answer on June 7, 2026 at 10:40 pm

    How to handle this exception and why my objectName is null here?

    objectName is not going to be null. The more likely scenario is that Type.GetTypeFromProgID(objectName) is returning null, because that prog-id doesn’t exist, or the account doesn’t have access.

    Check what Type.GetTypeFromProgID(objectName) returns, and act accordingly. Make sure it is actually a prog-id, and that you are using that API correctly. For example:

    var type = Type.GetTypeFromProgID(objectName);
    if(type == null) throw new InvalidOperationException(
        "Invalid prog-id: " + objectName);
    dynamic objUser = Activator.CreateInstance(type);
    

    Edit: Note that Activator.CreateInstance etc is not the same as VBScript’s GetObject. To access that, reference Microsoft.VisualBasic.dll, and use:

    dynamic obj = Microsoft.VisualBasic.Interaction.GetObject(objectName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this error in ElementTree when I try to run the code below:
So, when I try and run this line of code, I'm getting the following
I keep keep getting the above error when I run the code below. All
When I try to run this code, I get incorrect maximums and minimums. Could
When I try to run a routine I get the following error: Error Code:
This Java code compiles fine, but when I try to run it I get:
I have the given view and template code, when i try to run this
Thanks in advance. This is my sample code. Whenever i try to run it
Below is the insert function in VC++. I am getting this error when I
G'day folks I keep getting the error above whenever I run this and buggered

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.