You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Getting ArgumentNullException exception on calling System.Management.Automation.PowerShell.Create() when publishing a single file exe #24070
System.ArgumentNullException: Value cannot be null.(Parameter 'path1')
at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
at System.Management.Automation.PowerShell.EndInvoke(IAsyncResultasyncResult)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResultiar, Func`2endFunction, Action`1endAction, Task`1promise,BooleanrequiresSynchronization)---Endof stack trace from previous location ---
Expected behavior
should not throw exception.
Actual behavior
Throwing System.ArgumentNullException exception
Error details
No response
Environment data
Name Value
---------
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Microsoft Windows 10.0.22621
Platform Win32NT
PSCompatibleVersions {1.0,2.0,3.0,4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
I believe the problem is that PowerShell uses the location of System.Management.Automation.dll to get the location of $PSHOME which is what fails when built into a single exe. I was working on a change to allow building pwsh as a singleexe (which as other problems), but I can submit a simple change that would (I think) fix your problem.
Get the same issue on a Windows PC, if using the following DLL based on .NET Framework 4.8.1 with PowerShell v5.1 <System.Management.Automation> with .NET v8 SingleFile EXE.
<Issue.PowerShell_v5 with <System.Management.Automation> v2.0.50727>:
using System;
using System.Management.Automation;
namespace Issue.PowerShell_v5
{
public class PowerShellExecutor
{
public void ExecuteScript(string script)
{
using (PowerShell powerShell = PowerShell.Create())
{
powerShell.AddScript(script);
var results = powerShell.Invoke();
foreach (var result in results)
{
Console.WriteLine(result.ToString());
}
}
}
}
}
Run the SingleFile EXE, get mentioned errors as well, if using PowerShell v5 too:
Expected behavior
PowerShell v5 should run without any exceptions in this case.
############################
20240802: Update (1) , why my exception failed in .NET 8 using PS v5.x:
Will check my code again- I'm sorry if it's my code.
############################
20240802: Update (2)
############################
20240802: Update (3)
In my case, using PowerShell v5 within .NET 8 could be work at Windows >=v10 using RunspaceFactory.CreateOutOfProcessRunspace
using (Runspace runspace = RunspaceFactory.CreateOutOfProcessRunspace(
new TypeTable(Array.Empty<string>()),
new PowerShellProcessInstance(new Version(5, 1), null, null, false)
))
.....
Activity
SteveL-MSFT commentedon Jul 22, 2024
I believe the problem is that PowerShell uses the location of System.Management.Automation.dll to get the location of $PSHOME which is what fails when built into a single exe. I was working on a change to allow building pwsh as a singleexe (which as other problems), but I can submit a simple change that would (I think) fix your problem.
kasini3000 commentedon Jul 22, 2024
#23797
#13540
Such a big repair, thank you ! I will tell my father
mySCHOTT commentedon Aug 1, 2024
Not sure, if https://github.com/PowerShell/PowerShell/pull/24072 fix/solve the issue.
Steps to reproduce
<Issue.PowerShell_v5 with <System.Management.Automation> v2.0.50727>:
And with following <App.config>:
<Issue.PowerShell_v7>:
<FolderProfile.pubxml>:
Expected behavior
PowerShell v5 should run without any exceptions in this case.
############################

20240802: Update (1) , why my exception failed in .NET 8 using PS v5.x:
Will check my code again- I'm sorry if it's my code.
############################

20240802: Update (2)
############################
20240802: Update (3)
In my case, using PowerShell v5 within .NET 8 could be work at Windows >=v10 using RunspaceFactory.CreateOutOfProcessRunspace
SteveL-MSFT commentedon Aug 19, 2024
mySCHOTT there is no intent to support WinPS5.1 with single-exe
microsoft-github-policy-service commentedon Aug 19, 2024
📣 Hey Shreyansh Gupta (@kawaiifoxx), how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback