Skip to content

WIP AssemblyLoadContext - #1219

Closed
Andy Jordan (andyleejordan) wants to merge 16 commits into
andschwa/rtmfrom
andschwa/alc-wip
Closed

Andy Jordan (andyleejordan) wants to merge 16 commits into
andschwa/rtmfrom
andschwa/alc-wip

Conversation

@andyleejordan

Copy link
Copy Markdown
Member

This is work-in-progress to resolve #839.

This mimics the deprecated InitializeDefaultLoadContext by loading our top-level DLL (in this case, ConsoleHost) from the loader shim (src/powershell) manually with the ALC, then invoking its entry-point via reflection. In this way, all subsequent libraries are loaded through the same ALC (ours).

This also reverts the ClrFacade.Load work-around I'd introduced, as this should mean all assemblies are intercepted correctly.

This PR contains debugging and unfinished code, and exists solely to share with Dongbo Wang (@daxian-dbw).

@andyleejordan

Copy link
Copy Markdown
Member Author

Additionally, .NET Core 1.0 correctly does not throw when loading assemblies that are in the TPA, so try/catch logic that was introduced in the ALC was removed.

Note that this does not quite work. PowerShell loads, but there are some assembly loading issues, heh.

@andyleejordan

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw) sergei (@vors) BTW I ported the type catalog generator to .NET Core 😄

@andyleejordan

Copy link
Copy Markdown
Member Author

One problem we need to solve is that, right now, the whole project must be published, since the only path we start with is System.AppContext.BaseDirectory i.e. $PsHome. It should be pretty trivial to use the same logic in the parser to add the paths to every package we're using on start-up, so that we can still use dotnet build.

@andyleejordan

Andy Jordan (andyleejordan) commented Jun 27, 2016 •

Copy link
Copy Markdown
Member Author

Woah. This is working. That is, if I cd to the publish directory and launch it right there, it works.

~\src\PowerShell\src\powershell\bin\Debug\netcoreapp1.0\win10-x64\publish |-/ .\powershell.exe
Attempting to Load Microsoft.PowerShell.ConsoleHost, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Attempting to Load System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Attempting to Load Microsoft.PowerShell.CoreCLR.Eventing, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Attempting to Load System.Runtime.Serialization.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load Microsoft.Win32.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load Microsoft.Win32.Registry, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Resources.ResourceManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Diagnostics.Process, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Diagnostics.FileVersionInfo, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Dynamic.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Threading.Thread, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Linq.Expressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Diagnostics.TraceSource, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Xml.ReaderWriter, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Collections.NonGeneric, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Attempting to Load System.Text.RegularExpressions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Runtime.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Threading.Overlapped, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Security.SecureString, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Net.Primitives, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Xml.XmlDocument, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Security.AccessControl, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Reflection, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Reflection.TypeExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Linq, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Security.Principal, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Data.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Reflection.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Reflection.Emit.ILGeneration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Diagnostics.Debug, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Reflection.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Reflection.Emit.Lightweight, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

Attempting to Load System.ObjectModel, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Diagnostics.Tracing, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Security.Principal.Windows, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Security.Claims, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Globalization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Reflection.Emit, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Threading.Timer, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Collections.Specialized, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Threading.Tasks.Parallel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load Microsoft.PowerShell.Security, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Attempting to Load System.IO.FileSystem.DriveInfo, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.ComponentModel.TypeConverter, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Security.Cryptography.X509Certificates, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Security.Cryptography.Encoding, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.IO.FileSystem.AccessControl, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load Microsoft.Win32.Registry.AccessControl, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load System.Threading.ThreadPool, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load Microsoft.PowerShell.PSReadLine, Culture=neutral, PublicKeyToken=null
Attempting to Load Microsoft.CSharp, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Attempting to Load Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Loading personal and system profiles took 620ms.
Attempting to Load Microsoft.PowerShell.Commands.Management, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Attempting to Load System.ServiceProcess.ServiceController, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
~\src\PowerShell\src\powershell\bin\Debug\netcoreapp1.0\win10-x64\publish |-/

Given that I have debugging code in this, that's the exact output I was expecting.

@andyleejordan

Andy Jordan (andyleejordan) commented Jun 27, 2016 •

Copy link
Copy Markdown
Member Author

Not all tests are passing, as some methods aren't getting found (as if implicit loading isn't working), but it's progress.

Dongbo Wang (@daxian-dbw) can we see your changes too? I'd like to converge.

@andyleejordan

Copy link
Copy Markdown
Member Author

Actually, this is very promising. It looks like all the "missing methods" are coming just from Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions, so at least it's just one problem, not many.

@andyleejordan

Copy link
Copy Markdown
Member Author
   Method not found: 'Void Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions..ctor(Microsoft.CodeAnalysis.OutputKind, System.String, System.String, System.String, System.Collections.Generic.IEnumerable`1<System.String>, Microsoft.CodeAnalysis.OptimizationLevel, Bool
ean, Boolean, System.String, System.String, System.Collections.Immutable.ImmutableArray`1<Byte>, System.Nullable`1<Boolean>, Microsoft.CodeAnalysis.Platform, Microsoft.CodeAnalysis.ReportDiagnostic, Int32, System.Collections.Generic.IEnumerable`1<System.Collections.Gener
ic.KeyValuePair`2<System.String,Microsoft.CodeAnalysis.ReportDiagnostic>>, Boolean, Boolean, Microsoft.CodeAnalysis.XmlReferenceResolver, Microsoft.CodeAnalysis.SourceReferenceResolver, Microsoft.CodeAnalysis.MetadataReferenceResolver, Microsoft.CodeAnalysis.AssemblyIden
tityComparer, Microsoft.CodeAnalysis.StrongNameProvider)'.

sergei (@vors) does this mean anything to you?

@andyleejordan

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw) I'm probably going to pull out the Start-TypeGen changes and port of the generator out of this and into #1210, so we can keep working on this and #1228.

Sergei Vorobev and others added 6 commits June 28, 2016 12:59
Exclude Microsoft.WSMan.Management from the list of default snapins
Update PowerShell to use .NET Core 1.0
Add simple test for non-empty workflow, make it work
Instead, rely on intercepting Assembly.Load
@andyleejordan

Copy link
Copy Markdown
Member Author

Ah I need to change the base branch. Closing and re-opening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants