Title: Issue Adding Custom Type Definition When ref Directory Does Not Exist · Issue #11139 · PowerShell/PowerShell · GitHub
Open Graph Title: Issue Adding Custom Type Definition When ref Directory Does Not Exist · Issue #11139 · PowerShell/PowerShell
X Title: Issue Adding Custom Type Definition When ref Directory Does Not Exist · Issue #11139 · PowerShell/PowerShell
Description: When the netcore2.1\ref (or other netcore*\ref folder) does not exist, the Directory.EnumerateFiles fails to enumerate assemblies as expected. However because the error is not caught, the custom type fails to be declared even if the ref ...
Open Graph Description: When the netcore2.1\ref (or other netcore*\ref folder) does not exist, the Directory.EnumerateFiles fails to enumerate assemblies as expected. However because the error is not caught, the custom ty...
X Description: When the netcore2.1\ref (or other netcore*\ref folder) does not exist, the Directory.EnumerateFiles fails to enumerate assemblies as expected. However because the error is not caught, the custom ty...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/11139
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Issue Adding Custom Type Definition When ref Directory Does Not Exist","articleBody":"\u003c!--\r\n\r\nFor Windows PowerShell 5.1 issues, suggestions, or feature requests please use the following link instead:\r\nWindows PowerShell [UserVoice](https://windowsserver.uservoice.com/forums/301869-powershell)\r\n\r\nThis repository is **ONLY** for PowerShell Core 6 issues.\r\n\r\n- Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- Search the existing issues.\r\n- Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- Refer to the [known issues](https://docs.microsoft.com/powershell/scripting/whats-new/known-issues-ps6?view=powershell-6).\r\n\r\n-->\r\n\r\nWhen the netcore2.1\\ref (or other netcore*\\ref folder) does not exist, the Directory.EnumerateFiles fails to enumerate assemblies as expected. However because the error is not caught, the custom type fails to be declared even if the ref folder and reference assemblies are not needed for the definition.\r\n\r\nThis was discovered on Azure Functions for PowerShell because the PowerShell worker directories don't contain the ref subfolder. While this could be fixed in the Azure Functions Host, it should be handled gracefully in case other applications are deployed in a similar way.\r\n\r\n# Steps to reproduce\r\n\r\nUsing Azure Functions for PowerShell, attempt to load a custom Type Definition with Add-Type. This is taken from ACME-PS:\r\n\r\n```powershell\r\n$interfaces = @\"\r\npublic interface IKey\r\n{\r\n object ExportKey();\r\n}\r\n\"@\r\n\r\nAdd-Type -TypeDefinition $interfaces\r\n```\r\n\r\n# Expected behavior\r\n\r\nType definition is loaded successfully\r\n\r\n# Actual behavior\r\n\r\n```none\r\n2019-11-20T21:22:50.294 [Error] ERROR: Add-Type : Could not find a part of the path 'D:\\Program Files (x86)\\SiteExtensions\\Functions\\2.0.12858\\32bit\\workers\\powershell\\runtimes\\win-x86\\lib\\netcoreapp2.1\\ref'.\r\nAt D:\\home\\site\\wwwroot\\Modules\\ACME-PS\\1.1.1\\TypeDefinitions.ps1:25 char:1\r\n+ Add-Type -TypeDefinition $interfaces\r\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n+ CategoryInfo : NotSpecified: (:) [Add-Type], DirectoryNotFoundException\r\n+ FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.AddTypeCommand\r\n\r\nScript stack trace:\r\n at \u003cScriptBlock>, D:\\home\\site\\wwwroot\\Modules\\ACME-PS\\1.1.1\\TypeDefinitions.ps1: line 25\r\n at Update-AzWebAppCertificateLE, D:\\home\\site\\wwwroot\\Modules\\SALInfrastructureFunctions\\Export\\Update-AzWebAppCertificateLE.ps1: line 66\r\n at \u003cScriptBlock>, D:\\home\\site\\wwwroot\\GenericHttp\\run.ps1: line 80\r\n\r\nSystem.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\\Program Files (x86)\\SiteExtensions\\Functions\\2.0.12858\\32bit\\workers\\powershell\\runtimes\\win-x86\\lib\\netcoreapp2.1\\ref'.\r\n at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)\r\n at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, EnumerationOptions options)\r\n at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options)\r\n at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)\r\n at System.IO.Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)\r\n at System.IO.Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)\r\n at Microsoft.PowerShell.Commands.AddTypeCommand.InitDefaultRefAssemblies()\r\n at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)\r\n at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)\r\n at System.Lazy`1.CreateValue()\r\n at System.Lazy`1.get_Value()\r\n at Microsoft.PowerShell.Commands.AddTypeCommand.GetPortableExecutableReferences()\r\n at Microsoft.PowerShell.Commands.AddTypeCommand.CompileToAssembly(List`1 syntaxTrees, CompilationOptions compilationOptions, EmitOptions emitOptions)\r\n at Microsoft.PowerShell.Commands.AddTypeCommand.SourceCodeProcessing()\r\n at Microsoft.PowerShell.Commands.AddTypeCommand.EndProcessing()\r\n at System.Management.Automation.Cmdlet.DoEndProcessing()\r\n at System.Management.Automation.CommandProcessorBase.Complete()\r\n```\r\n\r\n# Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable -->\r\n\r\n```none\r\nName Value\r\n---- -----\r\nPSVersion 6.2.3\r\nPSEdition Core\r\nGitCommitId 6.2.3\r\nOS Microsoft Windows 10.0.14393\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\r\n```\r\n","author":{"url":"https://github.com/nerddtvg","@type":"Person","name":"nerddtvg"},"datePublished":"2019-11-20T22:05:07Z","url":"https://github.com/PowerShell/PowerShell/issues/11139"}
| 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:e94c914e-e170-e538-a910-fb832a5ee1d2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 83FC:126CB9:259283E:344F2D4:6AFD44ED |
| html-safe-nonce | 2bf25c3056e7c945e000ec3bf678341d906c287dcdd479edcd52cf059b77356b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4M0ZDOjEyNkNCOToyNTkyODNFOjM0NEYyRDQ6NkFGRDQ0RUQiLCJ2aXNpdG9yX2lkIjoiNDQ1NTk4ODg2NDQyMjMzMTYyOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 943885de510aed98b04ccfe726e4e6285520c51d4cb8e2e72ba093c23cbbd40e |
| hovercard-subject-tag | issue:526242148 |
| 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/11139/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fca681f1bcb7800abf6525a858dc0005de9f7bdd5b4c5f95be9722260fbb3197/PowerShell/PowerShell/issues/11139 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fca681f1bcb7800abf6525a858dc0005de9f7bdd5b4c5f95be9722260fbb3197/PowerShell/PowerShell/issues/11139 |
| og:image:alt | When the netcore2.1\ref (or other netcore*\ref folder) does not exist, the Directory.EnumerateFiles fails to enumerate assemblies as expected. However because the error is not caught, the custom ty... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | nerddtvg |
| hostname | github.com |
| expected-hostname | github.com |
| None | bdbacc25b921224ff0befcb9e629560a1255be51aec9991d6e3f95b5e9151474 |
| 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 | 556dd37bb0aceffb25724e151b5d858b3265b40b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width