Title: New-Object doesn't work with classes in nested modules · Issue #2963 · PowerShell/PowerShell · GitHub
Open Graph Title: New-Object doesn't work with classes in nested modules · Issue #2963 · PowerShell/PowerShell
X Title: New-Object doesn't work with classes in nested modules · Issue #2963 · PowerShell/PowerShell
Description: Steps to reproduce Define some PowerShell classes in a module file (ClassTester.psm1). In the manifest, leave RootModule empty and place the module name in the NestedModules key value. ModuleToProcess = '' NestedModules = 'ClassTester.ps...
Open Graph Description: Steps to reproduce Define some PowerShell classes in a module file (ClassTester.psm1). In the manifest, leave RootModule empty and place the module name in the NestedModules key value. ModuleToProc...
X Description: Steps to reproduce Define some PowerShell classes in a module file (ClassTester.psm1). In the manifest, leave RootModule empty and place the module name in the NestedModules key value. ModuleToProc...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/2963
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"New-Object doesn't work with classes in nested modules","articleBody":"Steps to reproduce\r\n------------------\r\n1. Define some PowerShell classes in a module file (ClassTester.psm1).\r\n2. In the manifest, leave RootModule empty and place the module name in the NestedModules key value.\r\n```\r\nModuleToProcess = ''\r\nNestedModules = 'ClassTester.psm1'\r\n```\r\n3. In a script, use a Using module statement to import the module and its classes, use the New static method to instantiate one of the classes defined in ClassTester.psm1, and then use New-Object on the same class. \r\n\r\n```\r\nusing module ClassTester\r\n$myDog = [Dog]::New('Fido')\r\n$myDog.Bark()\r\n\r\nNew-Object -TypeName Dog -ArgumentList 'Fluffy'\r\n$myDog.Bark()\r\n```\r\n\r\nExpected behavior\r\n-----------------\r\nBoth the New method and New-Object cmdlet should work.\r\n\r\nActual behavior\r\n---------------\r\nNew works, but New-Object generates an error.\r\n\r\n```\r\n'Woof!,' said Fido # New method works\r\nNew-Object : Cannot find type [Dog]: verify that the assembly containing this type is loaded.\r\nAt C:\\ps-test\\Test-ClassTester.ps1:22 char:11\r\n+ $fluffy = New-Object -TypeName Dog -ArgumentList 'Fluffy'\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException\r\n + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand\r\n```\r\n\r\nEnvironment data\r\n----------------\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n```\r\nName Value\r\n---- -----\r\nGitCommitId v6.0.0-alpha.14\r\nPSRemotingProtocolVersion 2.3\r\nBuildVersion 3.0.0.0\r\nWSManStackVersion 3.0\r\nSerializationVersion 1.1.0.1\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}\r\nPSVersion 6.0.0-alpha\r\nPSEdition Core\r\nCLRVersion\r\n```\r\n","author":{"url":"https://github.com/juneb","@type":"Person","name":"juneb"},"datePublished":"2017-01-06T01:53:18Z","url":"https://github.com/PowerShell/PowerShell/issues/2963"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c3c0a6c4-db3d-5513-685a-e59bc5caf2c6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C84E:34BE8C:AFD74:FC4A8:6AFDC0B4 |
| html-safe-nonce | b4c6dbffd9c74a18bc8acc835d8bbe59932b2e497330671ab876dc1603b6153d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODRFOjM0QkU4QzpBRkQ3NDpGQzRBODo2QUZEQzBCNCIsInZpc2l0b3JfaWQiOiI4MDEzNjczMTM2NTY0MDYwMzQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 84b7a55ea3a8bccb470704887eece785bf1890b814c70cfcc52d5ef31c33aa68 |
| hovercard-subject-tag | issue:199106066 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/2963/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e21d45b990c31a48c1bfffc4d441a754417ff2ac04f37a206d76e617fd30232d/PowerShell/PowerShell/issues/2963 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e21d45b990c31a48c1bfffc4d441a754417ff2ac04f37a206d76e617fd30232d/PowerShell/PowerShell/issues/2963 |
| og:image:alt | Steps to reproduce Define some PowerShell classes in a module file (ClassTester.psm1). In the manifest, leave RootModule empty and place the module name in the NestedModules key value. ModuleToProc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | juneb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 35c6bf57da1370dc64866160540c0ee9f825f291935b3bf6ec5492b00e35f3a6 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ab48c73a2978548773f5f24717ed9e58508befdb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width