{"action":"opened","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2108","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2108/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2108/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/2108/events","html_url":"https://github.com/PowerShell/PowerShell/issues/2108","id":173646569,"number":2108,"title":"Cannot load Microsoft.PowerShell.Diagnostics when using the SDK on .Net Core on Windows","user":{"login":"svick","id":287848,"avatar_url":"https://avatars.githubusercontent.com/u/287848?v=3","gravatar_id":"","url":"https://api.github.com/users/svick","html_url":"https://github.com/svick","followers_url":"https://api.github.com/users/svick/followers","following_url":"https://api.github.com/users/svick/following{/other_user}","gists_url":"https://api.github.com/users/svick/gists{/gist_id}","starred_url":"https://api.github.com/users/svick/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svick/subscriptions","organizations_url":"https://api.github.com/users/svick/orgs","repos_url":"https://api.github.com/users/svick/repos","events_url":"https://api.github.com/users/svick/events{/privacy}","received_events_url":"https://api.github.com/users/svick/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-28T13:22:57Z","updated_at":"2016-08-28T13:22:57Z","closed_at":null,"body":"Steps to reproduce\r\n------------------\r\n\r\n1. Use Windows 10, `dotnet` CLI preview 2; don't install PowerShell Core.\r\n\r\n2. Create a .Net Core project that references `Microsoft.PowerShell.SDK` version 1.0.0-alpha9 from [the powershell-core MyGet feed](https://powershell.myget.org/gallery/powershell-core/).\r\n\r\n3. Add the following code to `Program.cs`:\r\n\r\n ```c#\r\n  using System.Management.Automation;\r\n\r\n  public class Program\r\n  {\r\n      public static void Main()\r\n      {\r\n          var ps = PowerShell.Create();\r\n\r\n          ps.AddCommand(\"gci\");\r\n\r\n          ps.Invoke();\r\n      }\r\n  }\r\n```\r\n [The complete project is here.](https://gist.github.com/svick/f230af474d9874c9ae7f976d12e4d405)\r\n\r\n4. `dotnet restore`, `dotnet run`.\r\n\r\nExpected behavior\r\n-----------------\r\n\r\n`ps.Invoke()` does not throw.\r\n\r\nActual behavior\r\n---------------\r\n\r\n`ps.Invoke()` thows:\r\n\r\n```\r\nSystem.Management.Automation.Runspaces.PSSnapInException: Cannot load Windows PowerShell snap-in Microsoft.PowerShell.Diagnostics because of the following error: Could not load file or assembly 'Microsoft.PowerShell.Commands'. The system cannot find the file specified.\r\n   at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)\r\n   at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo)\r\n   at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIns(Collection`1 mshsnapinInfos, PSConsoleLoadException& warning)\r\n   at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadConsole(PSConsoleLoadException& warning)\r\n   at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.CreateDefaultConfiguration()\r\n   at System.Management.Automation.Runspaces.RunspaceConfiguration.Create()\r\n   at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(PSHost host)\r\n   at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()\r\n   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)\r\n   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\r\n   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\r\n   at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)\r\n   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)\r\n   at System.Management.Automation.PowerShell.Invoke()\r\n   at Program.Main()\r\n```\r\n\r\nPuzzling things I found when looking into this:\r\n\r\n* There is no package for `Microsoft.PowerShell.Commands.Diagnostics`.\r\n* `PSSnapInReader.DefaultMshSnapins` [contains `Microsoft.PowerShell.Diagnostics` only when `UNIX` is not set](https://github.com/PowerShell/PowerShell/blob/d575308/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs#L1287-L1290). But there is only one `netstandard1.6` version of `System.Management.Automation.dll` in the `System.Management.Automation` 1.0.0-alpha9 package, compiled without the `UNIX` flag set.\r\n* `PSSnapInInfo.AbsoluteModulePath` [treats the `ModuleName` of `Microsoft.PowerShell.Commands.Diagnostics` as file name with extension](https://github.com/PowerShell/PowerShell/blob/d575308/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs#L254) and returns just `Microsoft.PowerShell.Commands` (as shown in the exception message above)."}}
{"actor":{"display_login":"svick"}}