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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:55:28+00:00 2026-05-25T06:55:28+00:00

I have a class that I define in inline C# in powershell: Add-Type -TypeDefinition

  • 0

I have a class that I define in inline C# in powershell:

Add-Type -TypeDefinition @"
    public class SomeClass {
        string name;
        public string Name { get { return name; } set { name = value; } }
        int a, b;
        public int A { get { return a; } set { a = value; } }
        public int B { get { return b; } set { b = value; } }
    }
"@

I can instantiate it:
$someClass= New-Object SomeClass -Property @{
‘Name’ = “Justin Dearing”;
“A” = 1;
“B” = 5;
};

But I cannot instantiate a list of it:

$listOfClasses = New-Object System.Collections.Generic.List[SomeClass];

Doing so gets me the following:

New-Object : Cannot find type [[System.Collections.Generic[SomeClass]]]: make sure the assembly containing this type is loaded.
At line:12 char:28
+ $listOfClasses = New-Object <<<<  [System.Collections.Generic[SomeClass]]
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
  • 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-25T06:55:29+00:00Added an answer on May 25, 2026 at 6:55 am

    It seems that is not directly supported in PowerShell. Here is a solution, which provides a New-GenericObject script; that does some reflection in order to create the correct type.

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

Sidebar

Related Questions

I have a class that defines a CallRate type. I need to add the
I have noticed that it is possible to define a custom class and then
I have a class that defines its own enum like this: public class Test
I have been trying to make a StringTable class that holds a simple unordered_map<string,
I have something like that (simplified) class A { public: virtual void Function ()
I have a class that defines the names of various session attributes, e.g. class
I have a class that defines a read-only property that effectively exposes a private
I have a class that defined a user defined operator for a TCHAR*, like
I have a Literal class that defines a text value and an ID. I
I have an actionscript file that defines a class that I would like to

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.