-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated load context example to actually show unloading.
- Loading branch information
Showing
2 changed files
with
50 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Samples/SampleProjects/LoadContext/TestAssemblyLoadContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
|
||
namespace LoadContext | ||
{ | ||
internal class TestAssemblyLoadContext : AssemblyLoadContext | ||
{ | ||
private readonly AssemblyDependencyResolver _resolver; | ||
|
||
public TestAssemblyLoadContext(string mainAssemblyToLoadPath) : base(isCollectible: true) | ||
{ | ||
_resolver = new AssemblyDependencyResolver(mainAssemblyToLoadPath); | ||
} | ||
|
||
protected override Assembly Load(AssemblyName name) | ||
{ | ||
string assemblyPath = _resolver.ResolveAssemblyToPath(name); | ||
if (assemblyPath != null) | ||
{ | ||
return LoadFromAssemblyPath(assemblyPath); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |