Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5156 from lambdageek/bug-57850+57851
[sre] Deal with ResolveEventHandler returning an AssemblyBuilder (Fixes #57850, #57851) Fix a couple of bugs in the situation where a `ResolveEventHandler` happens to return an `AssemblyBuilder`. * [#57850](https://bugzilla.xamarin.com/show_bug.cgi?id=57850) - if the `ResolveEventHandler` returns a reflection only assembly, throw a `FileNotFoundException` * [#57851](https://bugzilla.xamarin.com/show_bug.cgi?id=57851) - don't look for a `ReferenceAssemblyAttribute` on assemblies returned by a `ResolveEventHandler` if they happen to be an `AssemblyBuilder`. (the native code path to get there is to try and instantiate a custom attribute in some other assembly, hence the fairly convoluted test in `assemblyresolve_event5` and its helper files)
- Loading branch information
Showing
13 changed files
with
221 additions
and
5 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
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
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,63 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Reflection.Emit; | ||
|
||
|
||
public class TestAssemblyResolveEvent { | ||
public static int Main (String[] args) { | ||
// Regression test for https://bugzilla.xamarin.com/show_bug.cgi?id=57851 | ||
|
||
// If the custom attributes of an assembly trigger a | ||
// ResolveEventHandler, and that handler returns an | ||
// AssemblyBuilder, don't crash. | ||
var h = new MockResolver ("assemblyresolve_event5_label"); | ||
var aName = new AssemblyName ("assemblyresolve_event5_helper"); | ||
var a = AppDomain.CurrentDomain.Load (aName); | ||
var t = a.GetType ("MyClass"); | ||
h.StartHandling (); | ||
var cas = t.GetCustomAttributes (true); | ||
h.StopHandling (); | ||
return 0; | ||
} | ||
} | ||
|
||
|
||
public class MockResolver { | ||
private Assembly mock; | ||
private ResolveEventHandler d; | ||
private string theName; | ||
|
||
public MockResolver (string theName) { | ||
mock = CreateMock (theName); | ||
d = new ResolveEventHandler (HandleResolveEvent); | ||
this.theName = theName; | ||
} | ||
|
||
public void StartHandling () { | ||
AppDomain.CurrentDomain.AssemblyResolve += d; | ||
} | ||
|
||
public void StopHandling () { | ||
AppDomain.CurrentDomain.AssemblyResolve -= d; | ||
} | ||
|
||
public Assembly HandleResolveEvent (Object sender, ResolveEventArgs args) { | ||
Console.Error.WriteLine ("handling load of {0}", args.Name); | ||
if (args.Name.StartsWith (theName)) | ||
return mock; | ||
else | ||
return null; | ||
} | ||
|
||
private static Assembly CreateMock (string s) { | ||
var an = new AssemblyName (s); | ||
var ab = AssemblyBuilder.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run); | ||
var mb = ab.DefineDynamicModule (an.Name); | ||
|
||
var tb = mb.DefineType ("Foo", TypeAttributes.Public); | ||
tb.DefineDefaultConstructor (MethodAttributes.Public); | ||
tb.CreateType (); | ||
|
||
return ab; | ||
} | ||
} |
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,10 @@ | ||
using System; | ||
|
||
public class SimpleTypedAttribute : Attribute { | ||
public SimpleTypedAttribute (Type t) { } | ||
} | ||
|
||
[SimpleTypedAttribute(typeof(Foo))] /* Foo defined in the assemblyresolve_event5_label assembly */ | ||
public class MyClass { | ||
public MyClass () { } | ||
} |
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,5 @@ | ||
using System; | ||
|
||
public class Foo { | ||
public Foo () { } | ||
} |
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