Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use AssemblyLoadContext Name instead of AppDomain #9353

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use AssemblyLoadContext Name instead of AppDomain
  • Loading branch information
bording committed Oct 21, 2023
commit 23c813fa0f647fb5753112486e9f8da5f5374dac
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using System.Linq;
#endif
using System.Reflection;
#if FEATURE_ASSEMBLYLOADCONTEXT
using System.Runtime.Loader;
#endif
using Microsoft.Build.BackEnd.Logging;
using Microsoft.Build.Framework;

Expand Down Expand Up @@ -152,10 +155,15 @@ private void CurrentDomainOnAssemblyLoad(object? sender, AssemblyLoadEventArgs a
string? assemblyName = args.LoadedAssembly.FullName;
string assemblyPath = args.LoadedAssembly.IsDynamic ? string.Empty : args.LoadedAssembly.Location;
Guid mvid = args.LoadedAssembly.ManifestModule.ModuleVersionId;
#if FEATURE_ASSEMBLYLOADCONTEXT
// AssemblyLoadContext.GetLoadContext returns null when the assembly isn't a RuntimeAssembly, which should not be the case here.
// Name would only be null if the AssemblyLoadContext didn't supply a name, but MSBuildLoadContext does.
string appDomainDescriptor = AssemblyLoadContext.GetLoadContext(args.LoadedAssembly)?.Name ?? "Unknown";
#else
string? appDomainDescriptor = _appDomain.IsDefaultAppDomain()
? null
: $"{_appDomain.Id}|{_appDomain.FriendlyName}";

#endif

AssemblyLoadBuildEventArgs buildArgs = new(_context, _initiator, assemblyName, assemblyPath, mvid, appDomainDescriptor);

Expand Down
3 changes: 2 additions & 1 deletion src/Framework/AssemblyLoadBuildEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public AssemblyLoadBuildEventArgs(
public string? AssemblyName { get; private set; }
public string? AssemblyPath { get; private set; }
public Guid MVID { get; private set; }
// Null string indicates that load occurred on Default AppDomain (for both Core and Framework).
// Null string indicates that load occurred on Default AppDomain (for Framework).
// For Core, string won't be null.
public string? AppDomainDescriptor { get; private set; }

internal override void WriteToStream(BinaryWriter writer)
Expand Down