Skip to content

Commit 88abe67

Browse files
authored
Fix two tests for runincontext testing (#43457)
* Disable two tests for runincontext testing These tests are not compatible with running using the runincontext tool. * Reflect PR feedback - make the test work instead
1 parent 722b8a6 commit 88abe67

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/tests/Loader/CollectibleAssemblies/ByRefLocals/ByRefLocals.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111

1212
class Program
1313
{
14+
class TestALC : AssemblyLoadContext
15+
{
16+
AssemblyLoadContext m_parentALC;
17+
public TestALC(AssemblyLoadContext parentALC) : base("test", isCollectible: true)
18+
{
19+
m_parentALC = parentALC;
20+
}
21+
22+
protected override Assembly Load(AssemblyName name)
23+
{
24+
return m_parentALC.LoadFromAssemblyName(name);
25+
}
26+
}
27+
1428
static int Main(string[] args)
1529
{
1630
var holdResult = HoldAssembliesAliveThroughByRefFields(out GCHandle gch1, out GCHandle gch2);
@@ -74,7 +88,8 @@ static int HoldAssembliesAliveThroughByRefFields(out GCHandle gch1, out GCHandle
7488
[MethodImpl(MethodImplOptions.NoInlining)]
7589
private static ReadOnlySpan<byte> LoadAssembly(out GCHandle gchToAssembly)
7690
{
77-
var alc = new AssemblyLoadContext("test", isCollectible: true);
91+
var currentALC = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly());
92+
var alc = new TestALC(currentALC);
7893
var a = alc.LoadFromAssemblyPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Unloaded.dll"));
7994
gchToAssembly = GCHandle.Alloc(a, GCHandleType.WeakTrackResurrection);
8095

src/tests/Loader/CollectibleAssemblies/Statics/CollectibleStatics.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,24 @@
1111

1212
class Program
1313
{
14+
class TestALC : AssemblyLoadContext
15+
{
16+
AssemblyLoadContext m_parentALC;
17+
public TestALC(AssemblyLoadContext parentALC) : base("test", isCollectible: true)
18+
{
19+
m_parentALC = parentALC;
20+
}
21+
22+
protected override Assembly Load(AssemblyName name)
23+
{
24+
return m_parentALC.LoadFromAssemblyName(name);
25+
}
26+
}
27+
1428
static int Main(string[] args)
1529
{
16-
var alc = new AssemblyLoadContext("test", isCollectible: true);
30+
var currentALC = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly());
31+
var alc = new TestALC(currentALC);
1732
var a = alc.LoadFromAssemblyPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Unloaded.dll"));
1833

1934
var accessor = (IStaticTest)Activator.CreateInstance(a.GetType("StaticTest"));

0 commit comments

Comments
 (0)