Title: Classes inheriting from [System.Attribute] cannot be defined and used in the same PowerShell module · Issue #1762 · PowerShell/PowerShell · GitHub
Open Graph Title: Classes inheriting from [System.Attribute] cannot be defined and used in the same PowerShell module · Issue #1762 · PowerShell/PowerShell
X Title: Classes inheriting from [System.Attribute] cannot be defined and used in the same PowerShell module · Issue #1762 · PowerShell/PowerShell
Description: Steps to reproduce set-StrictMode -Version 'Latest' $PSDefaultParameterValues['*:ErrorAction'] = 'Stop' class TestAttribute : System.Attribute { } class TestClass { [int] [TestAttribute()] $i = 5 } S C:\Users\scbaker> Import-Module E:\tm...
Open Graph Description: Steps to reproduce set-StrictMode -Version 'Latest' $PSDefaultParameterValues['*:ErrorAction'] = 'Stop' class TestAttribute : System.Attribute { } class TestClass { [int] [TestAttribute()] $i = 5 }...
X Description: Steps to reproduce set-StrictMode -Version 'Latest' $PSDefaultParameterValues['*:ErrorAction'] = 'Stop' class TestAttribute : System.Attribute { } class TestClass { [int] [T...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/1762
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Classes inheriting from [System.Attribute] cannot be defined and used in the same PowerShell module","articleBody":"## Steps to reproduce\r\n\r\nset-StrictMode -Version 'Latest'\r\n$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'\r\n\r\nclass TestAttribute : System.Attribute {\r\n}\r\nclass TestClass {\r\n[int] [TestAttribute()] $i = 5\r\n}\r\n\r\n S C:\\Users\\scbaker> Import-Module E:\\tmp\\Test-Module2.psm1\r\n\r\nImport-Module : The invoked member is not supported before the type is created.\r\nAt line:1 char:1\r\n- Import-Module E:\\tmp\\Test-Module.psm1\r\n- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n- CategoryInfo : NotSpecified: (:) [Import-Module], NotSupportedException\r\n- FullyQualifiedErrorId : System.NotSupportedException,Microsoft.PowerShell.Commands.ImportModuleCommand\r\n\r\nScotia Baker:\r\n\r\nBecause class names aren't visible outside their defining module, the only workaround I've found is using Add-Type. Defining the attribute in another module using PS5 class support does not work due to lexical scoping of class names.\r\n\r\nISSUE:\r\n\r\nA custom attribute class cannot be defined and used within the same PowerShell module.\r\n\r\nIMPACT:\r\n\r\n(1) Debug time diagnosing the issue. The import failure does not say what member or type is involved, making debugging difficult.\r\n\r\n(2) An extra module must be created to define attribute classes regardless of logical code layout.\r\n\r\nThe primary impact is in the debugging time; an extra module may be ugly but it's easy enough. A fix for the issue is of course preferred.\r\n","author":{"url":"https://github.com/SteveL-MSFT","@type":"Person","name":"SteveL-MSFT"},"datePublished":"2016-08-12T19:47:14Z","url":"https://github.com/PowerShell/PowerShell/issues/1762"}
| 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:f4b241fe-66fb-ab43-8fc9-f8c3564a5d32 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8230:45051:38D96E:4FA88C:6AFDC4B1 |
| html-safe-nonce | 8085287d4269d99d49fb7d0a4777e182bae7d5e9222e46ad014a1b51be944f74 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MjMwOjQ1MDUxOjM4RDk2RTo0RkE4OEM6NkFGREM0QjEiLCJ2aXNpdG9yX2lkIjoiNjY0MDY2Njc3ODg4MTg2ODk3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 50e9d200d4e855edb1102b99d4d286493994238e143b619caa00eee0cab12c6b |
| hovercard-subject-tag | issue:170945653 |
| 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/1762/issue_layout |
| twitter:image | https://opengraph.githubassets.com/92736e5217cd1e7b7b804196ee8274a528ffafbfd1e3eaa4ff45edb61043a659/PowerShell/PowerShell/issues/1762 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/92736e5217cd1e7b7b804196ee8274a528ffafbfd1e3eaa4ff45edb61043a659/PowerShell/PowerShell/issues/1762 |
| og:image:alt | Steps to reproduce set-StrictMode -Version 'Latest' $PSDefaultParameterValues['*:ErrorAction'] = 'Stop' class TestAttribute : System.Attribute { } class TestClass { [int] [TestAttribute()] $i = 5 }... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SteveL-MSFT |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9ab00cc3b4fa90bbd3da70765dd38efc23cfa9d9b0930e41feea2bf67f60ecaf |
| 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 | 1b795ba060b92691fc16c5a12cf2bf95e83432b4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width