Debugging PoshUI
Debugging a hybrid application like PoshUI requires looking at both the PowerShell modules and the C# execution engine. This guide provides strategies for identifying and resolving issues in both layers.
Debugging PowerShell Modules
Verbose Output
Most PoshUI cmdlets support the -Verbose switch. This is the first step in troubleshooting module-level logic, such as serialization or state management.
Show-PoshUIWizard -VerboseScript-Scoped State
You can inspect the current state of the UI definition by looking at the script-scoped variables in the module:
- Wizard:
$script:CurrentWizard - Workflow:
$script:CurrentWorkflow
Since these are script-scoped, you may need to use Get-Variable with the module's scope if you are debugging from an external terminal.
Debugging the C# Engine (PoshUI.exe)
AppDebug Mode
When calling Show-PoshUIWizard or Show-PoshUIWorkflow, you can use the -AppDebug switch. This tells the C# engine to enable internal debugging features, such as more detailed error dialogs and logging.
Show-PoshUIWizard -AppDebugVisual Studio Debugging
If you have the source code, you can debug the UI engine directly:
- Open
WizardFramework.slnin Visual Studio. - Set the
Launcherproject as the StartUp project. - In the project properties, go to the Debug tab.
- Set Application arguments to point to a valid PoshUI temporary file (e.g.,
C:\Users\...\AppData\Local\Temp\PoshUI\debug.json). - Press F5 to start debugging.
Analyzing Logs
PoshUI's CMTrace-compatible logs are the most valuable resource for troubleshooting in production.
- Navigate to the
Logsfolder relative to your script. - Open the most recent
.logfile using CMTrace.exe. - Look for entries highlighted in Red (Error) or Yellow (Warning).
Common log indicators:
- Serialization Error: Indicates a problem converting your PowerShell definition to JSON.
- AST Parsing Error: Indicates a syntax issue in your
param()block or custom attributes. - WPF Binding Error: Usually indicates a mismatch between a control's
Nameand its internal ViewModel property.
Common Issues & Solutions
UI Fails to Launch
- Check: Is
PoshUI.exeblocked by Windows? Right-click the file and select "Unblock". - Check: Is the
.NET Framework 4.8installed? - Solution: Run your script with
-Verboseto see exactly which path the module is using to launch the EXE.
Dynamic Dropdown is Empty
- Check: Does the
-ScriptBlockreturn an array of strings? - Check: Did you include the
-DependsOnparameter? - Solution: Test your script block independently in a standard PowerShell terminal to ensure it returns the expected data.
Password Validation Fails
- Check: Are you using
-ValidationPattern? - Check: Does the regex work against the plaintext version of your test password?
- Solution: Remember that password validation happens inside the C# engine for security.
Next: Contributing
