Title: ConsoleApp hosting PowerShell fails when published as single file · Issue #13540 · PowerShell/PowerShell · GitHub
Open Graph Title: ConsoleApp hosting PowerShell fails when published as single file · Issue #13540 · PowerShell/PowerShell
X Title: ConsoleApp hosting PowerShell fails when published as single file · Issue #13540 · PowerShell/PowerShell
Description: Probably the wrong repo to report this and most likely I did something wrong. I get an exception when I try to create a runspace in a console application published as a single file. Runs fine when published normally. Steps to reproduce <...
Open Graph Description: Probably the wrong repo to report this and most likely I did something wrong. I get an exception when I try to create a runspace in a console application published as a single file. Runs fine when ...
X Description: Probably the wrong repo to report this and most likely I did something wrong. I get an exception when I try to create a runspace in a console application published as a single file. Runs fine when ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/13540
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ConsoleApp hosting PowerShell fails when published as single file","articleBody":"Probably the wrong repo to report this and most likely I did something wrong. I get an exception when I try to create a runspace in a console application **published as a single file**. Runs fine when published normally.\r\n\r\n## Steps to reproduce\r\n\r\n```none\r\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\r\n \u003cPropertyGroup\u003e\r\n \u003cOutputType\u003eExe\u003c/OutputType\u003e\r\n \u003cTargetFramework\u003enet5.0\u003c/TargetFramework\u003e\r\n \u003c/PropertyGroup\u003e\r\n \u003cItemGroup\u003e\r\n \u003cPackageReference Include=\"Microsoft.PowerShell.SDK\" Version=\"7.1.0-preview.6\" /\u003e\r\n \u003c/ItemGroup\u003e\r\n\u003c/Project\u003e\r\n```\r\n\r\n```csharp\r\nusing System;\r\nusing System.Management.Automation.Runspaces;\r\n\r\nnamespace ConsoleApp1\r\n{\r\n class Program\r\n {\r\n static void Main(string[] args)\r\n {\r\n var rs = RunspaceFactory.CreateRunspace();\r\n Console.WriteLine(\"Hello World!\");\r\n }\r\n }\r\n}\r\n\r\n```\r\n\r\n\r\n```none\r\ndotnet publish -r win-x64 --self-contained false /p:PublishSingleFile=true\r\n```\r\n\r\n## Expected behavior\r\n\r\n```none\r\nHello World\r\n```\r\n\r\n## Actual behavior\r\n\r\n```none\r\nUnhandled exception. System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSVersionInfo' threw an exception.\r\n ---\u003e System.ArgumentException: The path is empty. (Parameter 'path')\r\n at System.IO.Path.GetFullPath(String path)\r\n at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)\r\n at System.Management.Automation.PSVersionInfo..cctor()\r\n --- End of inner exception stack trace ---\r\n at System.Management.Automation.PSVersionInfo.get_PSVersion()\r\n at Microsoft.PowerShell.DefaultHost..ctor(CultureInfo currentCulture, CultureInfo currentUICulture)\r\n at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()\r\n at ConsoleApp1.Program.Main(String[] args)\r\n```\r\n\r\n## Environment data\r\n\r\n\u003c!-- provide the output of $PSVersionTable --\u003e\r\n\r\n```none\r\ndotnet --info\r\n.NET SDK (reflecting any global.json):\r\n Version: 5.0.100-preview.8.20417.9\r\n Commit: fc62663a35\r\n\r\nRuntime Environment:\r\n OS Name: Windows\r\n OS Version: 10.0.19041\r\n OS Platform: Windows\r\n RID: win10-x64\r\n Base Path: C:\\Program Files\\dotnet\\sdk\\5.0.100-preview.8.20417.9\\\r\n\r\nHost (useful for support):\r\n Version: 5.0.0-preview.8.20407.11\r\n Commit: bf456654f9\r\n\r\n.NET SDKs installed:\r\n 5.0.100-preview.8.20417.9 [C:\\Program Files\\dotnet\\sdk]\r\n\r\n.NET runtimes installed:\r\n Microsoft.NETCore.App 5.0.0-preview.8.20407.11 [C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App]\r\n Microsoft.WindowsDesktop.App 5.0.0-preview.8.20411.6 [C:\\Program Files\\dotnet\\shared\\Microsoft.WindowsDesktop.App]\r\n```\r\n","author":{"url":"https://github.com/stwehrli","@type":"Person","name":"stwehrli"},"datePublished":"2020-08-29T14:22:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":48},"url":"https://github.com/13540/PowerShell/issues/13540"}
| 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:2d7291b9-73e6-8836-8116-926c9ce072ab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DCD8:3372C3:DE3658:12EA16E:6A55612E |
| html-safe-nonce | 45309fdd95eea5d544f90ade7519d85f8c2f28a9afceb398ff036d103aef7bcd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQ0Q4OjMzNzJDMzpERTM2NTg6MTJFQTE2RTo2QTU1NjEyRSIsInZpc2l0b3JfaWQiOiI4Nzc3NjYyMDI2NTM5Njg4MjM4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 738610726d20da44b9e6e50f71fc6e8a89736ec084699dcde5ea5a0fa6a04763 |
| hovercard-subject-tag | issue:688542272 |
| 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/13540/issue_layout |
| twitter:image | https://opengraph.githubassets.com/20e4b3b18dd6f3bc6063754e48cc62ee4500b7f2989d36ec6fc07e9ca5c7b7ba/PowerShell/PowerShell/issues/13540 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/20e4b3b18dd6f3bc6063754e48cc62ee4500b7f2989d36ec6fc07e9ca5c7b7ba/PowerShell/PowerShell/issues/13540 |
| og:image:alt | Probably the wrong repo to report this and most likely I did something wrong. I get an exception when I try to create a runspace in a console application published as a single file. Runs fine when ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | stwehrli |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5665c84831ed9ac4fb79519c16c9c5580ba8092fb8bb6e3e72972ec7197348e |
| 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 | 8201d0b7bc32164c4662de52242e463a356df543 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width