Powershell: "Segmentation fault" when attempting to obtain a load context for the executing assembly

Created on 25 Apr 2017  路  5Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

$context = [System.Runtime.Loader.AssemblyLoadContext]::GetLoadContext([System.Reflection.Assembly]::GetExecutingAssembly())

Expected behavior

PowerShell or .NET Core handles the error gracefully, or perhaps the API call succeeds, if it's supposed to.

Actual behavior

[1]    40918 segmentation fault  powershell

Environment data

Name                           Value                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                             
PSVersion                      6.0.0-alpha                                                                                                                                                                                                       
PSEdition                      Core                                                                                                                                                                                                              
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                           
BuildVersion                   3.0.0.0                                                                                                                                                                                                           
GitCommitId                    v6.0.0-alpha.18                                                                                                                                                                                                   
CLRVersion                                                                                                                                                                                                                                       
WSManStackVersion              3.0                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                               
SerializationVersion           1.1.0.1

Cheers,
Trevor Sullivan

Issue-Bug Resolution-External Resolution-Fixed Waiting - DotNetCore

Most helpful comment

All 5 comments

[1] 40918 segmentation fault powershell

@daxian-dbw Could you please comment the Issue?

Ah, another AssemblyLoadContext bug. It doesn't work well with dynamic assemblies that are emitted on the fly. I believe it's related to https://github.com/dotnet/corefx/issues/18877
See the below C# repro

using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Loader;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            AssemblyName aName = new AssemblyName("Microsoft.PowerShell.Cmdletization.GeneratedTypes");
            AssemblyBuilder ab = AssemblyBuilder.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run);
            ModuleBuilder mb = ab.DefineDynamicModule(aName.Name);

            string fullEnumName = "Microsoft.PowerShell.Cmdletization.GeneratedTypes.TestEnum";
            Type underlyingType = typeof(Int32);
            EnumBuilder eb = mb.DefineEnum(fullEnumName, TypeAttributes.Public, underlyingType);

            eb.DefineLiteral("Single", 0);
            eb.DefineLiteral("Multiple", 1);

            TypeInfo ti = eb.CreateTypeInfo();

            Console.WriteLine("Dynamic assembly emitted: {0}", ti.Assembly.FullName);

            var loadContext = AssemblyLoadContext.GetLoadContext(ti.Assembly);
            Console.WriteLine("Yay"); // Program crashes, so this line never gets printed out
        }
    }
}
d:\cmdlet\Sample>dotnet run
Dynamic assembly emitted: Microsoft.PowerShell.Cmdletization.GeneratedTypes, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

d:\cmdlet\Sample>

I can not repo with Beta.8

Was this page helpful?
0 / 5 - 0 ratings