Title: ValidateSet with class does not work · Issue #19676 · PowerShell/PowerShell · GitHub
Open Graph Title: ValidateSet with class does not work · Issue #19676 · PowerShell/PowerShell
X Title: ValidateSet with class does not work · Issue #19676 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/19676
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ValidateSet with class does not work","articleBody":"### Prerequisites\n\n- [X] Write a descriptive title.\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [X] Search the existing issues.\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://docs.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nCreate two files in a directory.\r\n\r\ntest.ps1\r\n```\r\nusing module './testvalidate.psm1'\r\n\r\nparam\r\n(\r\n [Parameter(Mandatory)]\r\n [ValidateSet([TestValidate])]\r\n [string]$foo\r\n)\r\n```\r\n\r\ntestvalidate.psm1\r\n```\r\nclass TestValidate : System.Management.Automation.IValidateSetValuesGenerator\r\n{\r\n [String[]] GetValidValues()\r\n {\r\n $values = @()\r\n $values += 'bar'\r\n $values += 'baz'\r\n return $values\r\n }\r\n}\r\n```\n\n### Expected behavior\n\n```console\ncmdlet test.ps1 at command pipeline position 1\r\nSupply values for the following parameters:\r\nfoo:\n```\n\n\n### Actual behavior\n\n```console\nInvalidOperation: E:\\Software development\\Royalty Calculator\\trunk.powershell\\test.ps1:6\r\nLine |\r\n 6 | [ValidateSet([TestValidate])]\r\n | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n | Unable to find type [TestValidate].\n```\n\n\n### Error details\n\n```console\nException :\r\n Type : System.Management.Automation.RuntimeException\r\n ErrorRecord :\r\n Exception :\r\n Type : System.Management.Automation.ParentContainsErrorRecordException\r\n Message : Unable to find type [TestValidate].\r\n HResult : -2146233087\r\n TargetObject : [ValidateSet([TestValidate])]\r\n CategoryInfo : InvalidOperation: ([ValidateSet([TestValidate])]:AttributeAst) [], ParentContainsErrorRecordException\r\n FullyQualifiedErrorId : TypeNotFound\r\n InvocationInfo :\r\n ScriptLineNumber : 6\r\n OffsetInLine : 5\r\n HistoryId : -1\r\n ScriptName : E:\\Software development\\Royalty Calculator\\trunk.powershell\\test.ps1\r\n Line : [ValidateSet([TestValidate])]\r\n\r\n PositionMessage : At E:\\Software development\\Royalty Calculator\\trunk.powershell\\test.ps1:6 char:5\r\n + [ValidateSet([TestValidate])]\r\n + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n PSScriptRoot : E:\\Software development\\Royalty Calculator\\trunk.powershell\r\n PSCommandPath : E:\\Software development\\Royalty Calculator\\trunk.powershell\\test.ps1\r\n CommandOrigin : Internal\r\n ScriptStackTrace : at \u003cScriptBlock>, \u003cNo file>: line 1\r\n TargetSite :\r\n Name : NewValidateSetAttribute\r\n DeclaringType : System.Management.Automation.Language.Compiler, System.Management.Automation, Version=7.3.4.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35\r\n MemberType : Method\r\n Module : System.Management.Automation.dll\r\n Message : Unable to find type [TestValidate].\r\n Data : System.Collections.ListDictionaryInternal\r\n Source : System.Management.Automation\r\n HResult : -2146233087\r\n StackTrace :\r\n at System.Management.Automation.Language.Compiler.NewValidateSetAttribute(AttributeAst ast)\r\n at System.Management.Automation.Language.Compiler.GetAttribute(AttributeAst attributeAst)\r\n at System.Management.Automation.Language.Compiler.GetRuntimeDefinedParameter(ParameterAst parameterAst, Boolean& customParameterSet, Boolean& usesCmdletBinding)\r\n at System.Management.Automation.Language.Compiler.GetParameterMetaData(ReadOnlyCollection`1 parameters, Boolean automaticPositions, Boolean& usesCmdletBinding)\r\n at System.Management.Automation.CompiledScriptBlockData.InitializeMetadata()\r\n at System.Management.Automation.CompiledScriptBlockData.Compile(Boolean optimized)\r\n at System.Management.Automation.PSScriptCmdlet..ctor(ScriptBlock scriptBlock, Boolean useNewScope, Boolean fromScriptFile, ExecutionContext context)\r\n at System.Management.Automation.CommandProcessor.Init(IScriptCommandInfo scriptCommandInfo)\r\n at System.Management.Automation.CommandDiscovery.GetScriptAsCmdletProcessor(IScriptCommandInfo scriptCommandInfo, ExecutionContext context, Boolean useNewScope, Boolean fromScriptFile, SessionStateInternal sessionState)\r\n at System.Management.Automation.CommandDiscovery.CreateCommandProcessorForScript(ExternalScriptInfo scriptInfo, ExecutionContext context, Boolean useNewScope, SessionStateInternal sessionState)\r\n at System.Management.Automation.CommandDiscovery.CreateScriptProcessorForSingleShell(ExternalScriptInfo scriptInfo, ExecutionContext context, Boolean useLocalScope, SessionStateInternal sessionState)\r\n at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, Nullable`1 useLocalScope, SessionStateInternal sessionState)\r\n at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)\r\n at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)\r\n at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)\r\n at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)\r\n at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)\r\n at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)\r\nTargetObject : [ValidateSet([TestValidate])]\r\nCategoryInfo : InvalidOperation: ([ValidateSet([TestValidate])]:AttributeAst) [], RuntimeException\r\nFullyQualifiedErrorId : TypeNotFound\r\nInvocationInfo :\r\n ScriptLineNumber : 6\r\n OffsetInLine : 5\r\n HistoryId : -1\r\n ScriptName : E:\\Software development\\Royalty Calculator\\trunk.powershell\\test.ps1\r\n Line : [ValidateSet([TestValidate])]\r\n\r\n PositionMessage : At E:\\Software development\\Royalty Calculator\\trunk.powershell\\test.ps1:6 char:5\r\n + [ValidateSet([TestValidate])]\r\n + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n PSScriptRoot : E:\\Software development\\Royalty Calculator\\trunk.powershell\r\n PSCommandPath : E:\\Software development\\Royalty Calculator\\trunk.powershell\\test.ps1\r\n CommandOrigin : Internal\r\nScriptStackTrace : at \u003cScriptBlock>, \u003cNo file>: line 1\n```\n\n\n### Environment data\n\n```powershell\nName Value\r\n---- -----\r\nPSVersion 7.3.4\r\nPSEdition Core\r\nGitCommitId 7.3.4\r\nOS Microsoft Windows 10.0.19045\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\n```\n\n\n### Visuals\n\n_No response_","author":{"url":"https://github.com/MarcelVersteeg","@type":"Person","name":"MarcelVersteeg"},"datePublished":"2023-05-18T22:36:25Z","url":"https://github.com/PowerShell/PowerShell/issues/19676"}
| 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:0a5db273-5ac2-e4e4-d900-4e7b91b48fcc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A37E:3E0E71:CD4B61:1205BDC:6AFDD3B5 |
| html-safe-nonce | ec924d4c2e0b0b819947e0750bb88f5573f9f9f541fe73d22f46d49f254a89cf |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzdFOjNFMEU3MTpDRDRCNjE6MTIwNUJEQzo2QUZERDNCNSIsInZpc2l0b3JfaWQiOiI3NDgyMzQyMzc1ODkzNjE5NjM3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f63ebdc4fbf0020d80268a4320078c59098161fbe3b5418231bf61b76b60c45e |
| hovercard-subject-tag | issue:1716350568 |
| 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/19676/issue_layout |
| twitter:image | https://opengraph.githubassets.com/92e39e7b68615b666671ddbbf3da4aefe155ed9919c5bdf475f9ab8af20b7c21/PowerShell/PowerShell/issues/19676 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/92e39e7b68615b666671ddbbf3da4aefe155ed9919c5bdf475f9ab8af20b7c21/PowerShell/PowerShell/issues/19676 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MarcelVersteeg |
| hostname | github.com |
| expected-hostname | github.com |
| None | 26886a40b582b821a7a76351e0a2f42b6d6160854b6e2520db24f31fd7be5da7 |
| 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 | 68ebaa631a1d248d69ebde4b9c5defd3a19aeb2f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width