-
Notifications
You must be signed in to change notification settings - Fork 100
Description
π Bug Description
Utils.ValidateModuleManifest() fails with false positive "No author was provided" error when called via [PowerShell]::Create() runspace, even though the module manifest contains a valid Author field.
The issue occurs because PSModuleInfo.Author property returns empty string when the object is deserialized across PowerShell runspace boundary.
π Affected Code
File: src/code/Utils.cs
Lines: 1388-1403
public static bool ValidateModuleManifest(string moduleManifestPath, out string errorMsg)
{
using (System.Management.Automation.PowerShell pwsh = System.Management.Automation.PowerShell.Create())
{
results = pwsh.AddCommand("Test-ModuleManifest")
.AddParameter("Path", moduleManifestPath)
.Invoke(); // β Line 1388: Runspace call
if (pwsh.HadErrors)
{
if (results.Any())
{
PSModuleInfo psModuleInfoObj = results[0].BaseObject as PSModuleInfo;
if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author)) // β Line 1403: BUG HERE!
{
errorMsg = "No author was provided...";
return false;
}π¬ Root Cause
PSModuleInfo property deserialization fails when object crosses PowerShell runspace boundary.
Test Case 1: Direct Call (Works β )
$manifest = Test-ModuleManifest -Path "manifest.psd1"
$manifest.Author # β 'GrexyLoco' β
Test Case 2: Runspace Call (Fails β)
$pwsh = [PowerShell]::Create()
$results = $pwsh.AddCommand("Test-ModuleManifest").AddParameter("Path", "manifest.psd1").Invoke()
$psModuleInfo = $results[0].BaseObject
$psModuleInfo.Author # β '' (empty string) β
$pwsh.HadErrors # β False
$pwsh.Dispose()Comparison Table:
| Method | Call Type | Author Value | pwsh.HadErrors | Result |
|---|---|---|---|---|
| Direct | Test-ModuleManifest -Path |
'GrexyLoco' |
N/A | β Works |
| Runspace | [PowerShell]::Create() |
'' (empty) |
False |
β Fails |
π₯ Impact
Symptom: Publish-PSResource throws error:
No author was provided in the module manifest
Workaround Required:
Publish-PSResource -Path ./Module -Repository MyRepo -SkipModuleManifestValidateThis forces users to bypass validation entirely, which is not ideal for catching actual manifest issues.
π§ Suggested Fix
Option 1: Use direct Test-ModuleManifest call (preferred)
// Instead of runspace, use direct cmdlet invocation
var manifestValidation = InvokeCommand.InvokeScript(
$"Test-ModuleManifest -Path '{moduleManifestPath}'"
).FirstOrDefault()?.BaseObject as PSModuleInfo;Option 2: Serialize specific properties explicitly
// Request explicit property serialization before crossing runspace boundary
pwsh.AddCommand("Test-ModuleManifest")
.AddParameter("Path", moduleManifestPath);
var results = pwsh.Invoke();
var moduleInfo = results[0];
// Access properties via PSObject instead of BaseObject
string author = moduleInfo.Properties["Author"]?.Value?.ToString();Option 3: Add null/empty check with better error message
if (string.IsNullOrWhiteSpace(psModuleInfoObj.Author))
{
// Re-validate with direct call to confirm
var directTest = InvokeCommand.InvokeScript(
$"(Test-ModuleManifest -Path '{moduleManifestPath}').Author"
).FirstOrDefault()?.ToString();
if (!string.IsNullOrWhiteSpace(directTest))
{
// Runspace deserialization bug - use direct result
psModuleInfoObj.Author = directTest;
}
else
{
errorMsg = "No author was provided...";
return false;
}
}π§ͺ Reproduction Steps
- Create valid module manifest with
Author = 'TestAuthor' - Call
Publish-PSResource -Path ./Module -Repository MyRepo - Observe error: "No author was provided in the module manifest"
- Verify manifest with direct
Test-ModuleManifestβ works correctly
π Environment
- PSResourceGet Version: 1.1.1 (stable), 1.2.0-preview3
- PowerShell Version: 7.4.6
- OS: Windows 11, GitHub Actions (Ubuntu/Windows runners)
- Manifest File: Valid
.psd1with all required fields includingAuthor
π References
- Utils.cs ValidateModuleManifest: https://github.com/PowerShell/PSResourceGet/blob/master/src/code/Utils.cs#L1388-1403
- Related workaround in user code: K.PSGallery.PackageRepoProvider.GitHub/Invoke-Publish.ps1
β Expected Behavior
ValidateModuleManifest() should correctly read Author property from module manifest regardless of execution context (direct vs runspace).
β Actual Behavior
Author property returns empty string when PSModuleInfo object is returned from [PowerShell]::Create() runspace, causing false positive validation failure.
This bug forces users to disable manifest validation entirely via -SkipModuleManifestValidate, which defeats the purpose of the validation.