KEMBAR78
By default, PowerShell Remoting isn't working in Asp.Net Core SDK 5.0 projects due to use of BinaryFormatter serialization · Issue #14032 · PowerShell/PowerShell · GitHub
Skip to content

By default, PowerShell Remoting isn't working in Asp.Net Core SDK 5.0 projects due to use of BinaryFormatter serialization #14032

@LeonarddeR

Description

@LeonarddeR

I have an asp.net core application that uses out of process PowerShell.

Steps to reproduce

Create a project with the following code:

using System;
using System.Management.Automation.Runspaces;

PowerShellProcessInstance instance = new PowerShellProcessInstance(
                powerShellVersion: new Version(5, 1),
                credential: null,
                initializationScript: null,
                useWow64: false
);
var runspace = RunspaceFactory.CreateOutOfProcessRunspace(null, instance);
runspace.Open();
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="system.management.automation" Version="7.0.3" />
  </ItemGroup>

</Project>

Note, also happens w ith System.Management.Automation 7.1.0 (most recent rc)

Expected behavior

Runspace opens properly.

Actual behavior

An exception is raised:

An error has occurred which PowerShell cannot handle. A remote session might have ended.

Inner exception:

BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.

Additional details

  1. The issue does not occur when using the default project sdk (not the web one)
  2. BinaryFormatter should probably not be used, see BinaryFormatter long-term obsoletion plan dotnet/designs#141

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aWG-DevEx-SDKhosting PowerShell as a runtime, PowerShell's APIs, PowerShell Standard, or development of modules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions