-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[loader] ReflectionOnlyLoad(byte[]) should not apply binding redirects (
#18457) * [loader] ReflectionOnlyLoad(byte[]) should not apply binding redirects Match .NET Framework behavior. Addresses #18388 * [tests] ReflectionOnlyLoad(byte[]) should not apply binding redirects Regression test for #18388
- Loading branch information
1 parent
f4567e8
commit e7e81a4
Showing
4 changed files
with
74 additions
and
2 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
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
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,55 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
public class TestAssemblyLoad { | ||
|
||
public static int Main () | ||
{ | ||
return TestDriver.RunTests (typeof (TestAssemblyLoad)); | ||
} | ||
|
||
public static int test_0_ReflectionOnlyLoadBytesBindingRedirect () | ||
{ | ||
|
||
string path1 = Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "assembly-load-dir1", "LibStrongName.dll"); | ||
|
||
// Try to load from dir1/LibStrongName.dll, despite | ||
// the assembly-refonly-load-bytes-bindingredirect.exe.config redirecting old versions to | ||
// be mapped to version 2.0.0.0 which is in the assembly-load-dir2 directory | ||
// | ||
// The binding redict should not apply to reflection-only loads. | ||
byte[] bytes1 = File.ReadAllBytes (path1); | ||
Assembly asm1 = Assembly.ReflectionOnlyLoad (bytes1); | ||
if (asm1 == null) { | ||
Console.Error.WriteLine ("expected asm1 {0} to not be null", asm1); | ||
return 1; | ||
} | ||
|
||
Type t1 = asm1.GetType ("LibClass"); | ||
if (t1 == null) { | ||
Console.Error.WriteLine ("expected t1 {0} to not be null", t1); | ||
return 2; | ||
} | ||
|
||
FieldInfo f1 = t1.GetField ("OnlyInVersion1"); | ||
if (f1 == null) { | ||
Console.Error.WriteLine ("expected to find field OnlyInVersion1, but got null"); | ||
return 3; | ||
} | ||
|
||
if (f1.FieldType != typeof(int)) { | ||
Console.Error.WriteLine ("Field OnlyInVersion1 has type {0}, expected int", f1.FieldType); | ||
return 5; | ||
} | ||
|
||
FieldInfo f2 = t1.GetField ("OnlyInVersion2"); | ||
|
||
if (f2 != null) { | ||
Console.Error.WriteLine ("expected not to find field OnlyInVersion2, but got {0}", f2); | ||
return 4; | ||
} | ||
|
||
return 0; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
mono/tests/assembly-refonly-load-bytes-bindingredirect.exe.config
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,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<runtime> | ||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
<probing privatePath="assembly-load-dir2"/> | ||
<dependentAssembly> | ||
<assemblyIdentity name="LibStrongName" publicKeyToken="537eab56aa911cb7" culture="neutral" /> | ||
<bindingRedirect oldVersion="0.0.0.0-1.0.0.0" newVersion="2.0.0.0" /> | ||
</dependentAssembly> | ||
</assemblyBinding> | ||
</runtime> | ||
</configuration> |