Microsoft.PowerShell.SDK Runspace Creation Exception with empty error message in .NET 6 with publish target win-x64 #18225
Labels
Resolution-Duplicate
The issue is a duplicate.
WG-DevEx-SDK
hosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules
Prerequisites
Steps to reproduce
For Microsoft.PowerShell.SDK version 7.2.6 running on Windows 11 and Windows Server 2016:
If you publish a .NET 6 console application (or any other exe type) with target framework win-x64 (instead of e.g. win7-x64)
There is an exception with an empty string message when you call:
RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault())
The issue occurs with published binaries, when the output runtime is set to win-x64.
The error has no message or inner exception, but has the following stack trace:
System.Reflection.RuntimeAssembly.GetExportedTypes(QCallAssembly assembly, ObjectHandleOnStack retTypes) at System.Reflection.RuntimeAssembly.GetExportedTypes() at System.Management.Automation.Runspaces.PSSnapInHelpers.GetAssemblyTypes(Assembly assembly, String name) at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, String helpFile, Dictionary
2& cmdlets, Dictionary2& aliases, Dictionary
2& providers) at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Dictionary2& cmdlets, Dictionary
2& aliases, Dictionary2& providers, String& helpFile) at System.Management.Automation.Runspaces.InitialSessionState.ImportPSSnapIn(PSSnapInInfo psSnapInInfo, PSSnapInException& warning) at System.Management.Automation.Runspaces.InitialSessionState.CreateDefault()
The following is a minimal project to reproduce the issue.
Project file:
Exe net6.0-windows PowerShellTest PowerShellTest true true true true win-x64 true embedded True x64 bin\Debug embedded True x64 bin\Release ``
Publish File:
<Project> <PropertyGroup> <Configuration>Release</Configuration> <Platform>x64</Platform> <PublishDir>publish\</PublishDir> <PublishProtocol>FileSystem</PublishProtocol> <_TargetId>Folder</_TargetId> <TargetFramework>net6.0-windows</TargetFramework> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <SelfContained>true</SelfContained> </PropertyGroup> </Project>
Program.cs File:
`using System;
using System.Management.Automation.Runspaces;
namespace PowerShellTest
{
class Program
{
static void Main(string[] args)
{
try
{
var runspace = RunspaceFactory.CreateRunspace(InitialSessionState.CreateDefault());
runspace.Open();
}
catch (Exception e)
{
Console.WriteLine($"Error: {e.Message}\r\n{e.StackTrace}");
}
}
}
}`
Expected behavior
Program runs without printing output
Actual behavior
Error details
No response
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: