Skip to content

Commit

Permalink
Fix AppDomain issues (dotnet/coreclr#25019)
Browse files Browse the repository at this point in the history
Populate AppDomain.CurrentDomain when invoking events
Make AppDomain method implemented in AssemblyLoadContext internal

Commit migrated from dotnet/coreclr@5d94217
  • Loading branch information
sdmaclea authored Jun 8, 2019
1 parent ecf84a9 commit 5f3ed6e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static class WindowsRuntimeMetadata
{
DesignerNamespaceResolveEventArgs eventArgs = new DesignerNamespaceResolveEventArgs(namespaceName);

handler(null /* AppDomain */, eventArgs);
handler(AppDomain.CurrentDomain, eventArgs);

Collection<string> assemblyFilesCollection = eventArgs.ResolvedAssemblyFiles;
if (assemblyFilesCollection.Count > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class AssemblyLoadContext
private static extern void LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, string? ilPath, string? niPath, ObjectHandleOnStack retAssembly);

[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Assembly[] GetLoadedAssemblies();
internal static extern Assembly[] GetLoadedAssemblies();

private Assembly InternalLoadFromPath(string? assemblyPath, string? nativeImagePath)
{
Expand Down Expand Up @@ -298,7 +298,7 @@ public void StartProfileOptimization(string profile)
// This method is called by the VM.
private static void OnAssemblyLoad(RuntimeAssembly assembly)
{
AssemblyLoad?.Invoke(null /* AppDomain */, new AssemblyLoadEventArgs(assembly));
AssemblyLoad?.Invoke(AppDomain.CurrentDomain, new AssemblyLoadEventArgs(assembly));
}

// This method is called by the VM.
Expand Down Expand Up @@ -328,7 +328,7 @@ private static void OnAssemblyLoad(RuntimeAssembly assembly)

foreach (ResolveEventHandler handler in eventHandler.GetInvocationList())
{
Assembly? asm = handler(null /* AppDomain */, args);
Assembly? asm = handler(AppDomain.CurrentDomain, args);
RuntimeAssembly? ret = GetRuntimeAssembly(asm);
if (ret != null)
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal static void OnProcessExit()
{
AssemblyLoadContext.OnProcessExit();

ProcessExit?.Invoke(null /* AppDomain */, EventArgs.Empty);
ProcessExit?.Invoke(AppDomain.CurrentDomain, EventArgs.Empty);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,20 @@ public event Action<AssemblyLoadContext> Unloading
}
}

#region AppDomainEvents
// Occurs when an Assembly is loaded
public static event AssemblyLoadEventHandler AssemblyLoad;
internal static event AssemblyLoadEventHandler AssemblyLoad;

// Occurs when resolution of type fails
public static event ResolveEventHandler TypeResolve;
internal static event ResolveEventHandler TypeResolve;

// Occurs when resolution of resource fails
public static event ResolveEventHandler ResourceResolve;
internal static event ResolveEventHandler ResourceResolve;

// Occurs when resolution of assembly fails
// This event is fired after resolve events of AssemblyLoadContext fails
public static event ResolveEventHandler AssemblyResolve;
internal static event ResolveEventHandler AssemblyResolve;
#endregion

public static AssemblyLoadContext Default => DefaultAssemblyLoadContext.s_loadContext;

Expand Down

0 comments on commit 5f3ed6e

Please sign in to comment.