summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCaio Kinelski <t-cakine@microsoft.com>2016-12-28 08:11:05 -0800
committerKoundinya Veluri <kouvel@microsoft.com>2016-12-28 08:11:05 -0800
commitd178b1287377a837773defb6b2a7f2b4e2dfc667 (patch)
treec8fb01e2f776a36964a263f1103d4d36c4fdeb5b /src
parent96400a730d7d4385c17f0930803ad79bd20edeb0 (diff)
downloadcoreclr-d178b1287377a837773defb6b2a7f2b4e2dfc667.tar.gz
coreclr-d178b1287377a837773defb6b2a7f2b4e2dfc667.tar.bz2
coreclr-d178b1287377a837773defb6b2a7f2b4e2dfc667.zip
Fix order of raising AssemblyLoadContext.Unloading and AppDomain.ProcessExit (#8737)
The AssemblyLoadContext.Unloading event must be raised before the AppDomain.ProcessExit event. AssemblyLoadContext.OnUnloading now subscribes to AppContext.Unloading. Then AppContext.OnAppContextUnloading and AppContext.OnProcessExit, in that order, subscribe to AppDomain.ProcessExit. Part of fix for dotnet/corefx#14566
Diffstat (limited to 'src')
-rw-r--r--src/mscorlib/src/System/AppContext/AppContext.cs41
-rw-r--r--src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs4
2 files changed, 29 insertions, 16 deletions
diff --git a/src/mscorlib/src/System/AppContext/AppContext.cs b/src/mscorlib/src/System/AppContext/AppContext.cs
index 41e44508f0..e318f93b89 100644
--- a/src/mscorlib/src/System/AppContext/AppContext.cs
+++ b/src/mscorlib/src/System/AppContext/AppContext.cs
@@ -19,6 +19,16 @@ namespace System
}
private static readonly Dictionary<string, SwitchValueState> s_switchMap = new Dictionary<string, SwitchValueState>();
+ static AppContext()
+ {
+ // Unloading event must happen before ProcessExit event
+ AppDomain.CurrentDomain.ProcessExit += OnUnloading;
+ AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
+
+ // populate the AppContext with the default set of values
+ AppContextDefaultValues.PopulateDefaultValues();
+ }
+
public static string BaseDirectory
{
get
@@ -73,25 +83,28 @@ namespace System
}
}
- public static event System.EventHandler ProcessExit
- {
- add
- {
- AppDomain.CurrentDomain.ProcessExit += value;
- }
- remove
- {
- AppDomain.CurrentDomain.ProcessExit -= value;
- }
+ public static event System.EventHandler ProcessExit;
+ public static event System.EventHandler Unloading;
+
+ private static void OnProcessExit(object sender, EventArgs e)
+ {
+ var processExit = ProcessExit;
+ if (processExit != null)
+ {
+ processExit(null, EventArgs.Empty);
+ }
}
- #region Switch APIs
- static AppContext()
+ private static void OnUnloading(object sender, EventArgs e)
{
- // populate the AppContext with the default set of values
- AppContextDefaultValues.PopulateDefaultValues();
+ var unloading = Unloading;
+ if (unloading != null)
+ {
+ unloading(null, EventArgs.Empty);
+ }
}
+ #region Switch APIs
/// <summary>
/// Try to get the value of the switch.
/// </summary>
diff --git a/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs b/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs
index e158a5aa8a..ee9861f604 100644
--- a/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs
+++ b/src/mscorlib/src/System/Runtime/Loader/AssemblyLoadContext.cs
@@ -75,7 +75,7 @@ namespace System.Runtime.Loader
// Since unloading an AssemblyLoadContext is not yet implemented, this is a temporary solution to raise the
// Unloading event on process exit. Register for the current AppDomain's ProcessExit event, and the handler will in
// turn raise the Unloading event.
- AppDomain.CurrentDomain.ProcessExit += OnProcessExit;
+ AppContext.Unloading += OnAppContextUnloading;
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
@@ -446,7 +446,7 @@ namespace System.Runtime.Loader
#endif // FEATURE_MULTICOREJI
}
- private void OnProcessExit(object sender, EventArgs e)
+ private void OnAppContextUnloading(object sender, EventArgs e)
{
var unloading = Unloading;
if (unloading != null)