Good morning, everyone!
I created a simple WPF application and followed the poshtools documentation to the letter. My PowerShell version is 7.0.3 (7.0.1 selected in Visual Studio) and .NET version is “netcoreapp31”.
When I hit F5, the application works just fine. But once it’s packaged as an exe, it never runs and I get the error below in Event Viewer.
Log Name: Application
Source: .NET Runtime
Date: 8/27/2020 7:21:36 AM
Event ID: 1026
Task Category: None
CoreCLR Version: 4.700.20.36602
.NET Core Version: 3.1.7
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Management.Automation.Host.HostException: The Win32 internal error “The handle is invalid.” 0x6 occurred while retrieving the handle for the active console output buffer. Contact Microsoft Customer Support Services.
—> System.ComponentModel.Win32Exception (6): The handle is invalid.
— End of inner exception stack trace —
at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, String args)
at Microsoft.PowerShell.ConsoleShell.Start(InitialSessionState initialSessionState, String bannerText, String helpText, String args)
at PowerShellToolsPro.Packager.ConsoleHost.Program.Main(String args)
When I open “cmd” and run it, the first error message I get is…
Cannot find path ‘C:\Users\me\source\repos\NGINXClientOnboarding\bin\Debug\System.Windows.Forms.dll’ because it does not exist.
The following exception occurred while retrieving member “Load”: “Could not load type ‘MS.Internal.SecurityCriticalDataForSet`1’ from assembly ‘WindowsBase, Version=184.108.40.206, Culture=neutral, PublicKeyToken=31bf3856ad364e35’.”
I’ve tried this on two different computers and get the same result. Does anyone have any suggestions on how to resolve this? I’ve already got the lines below at the top of my script.
Add-Type -AssemblyName PresentationFramework Add-Type -AssemblyName System.Windows.Forms
If it helps, here’s a screenshot of the “About” window in Visual Studio. I’m also running the latest version of PowerShell Pro Tools.
Thanks in advance for any help you can give!