Permalink
Browse files

2007-09-12 Marek Habersack <mhabersack@novell.com>

            * assemblyresolve_event2.2.cs: added tests for assembly resolution
            event handler.

            * assemblyresolve_event.cs: added tests for assembly resolution
            event handler.

2007-09-12  Marek Habersack  <mhabersack@novell.com>

            * appdomain.c (mono_runtime_init): do not install postload hooks -
            tests show that MS.NET doesn't use anything of that sort to
            trigger the AppDomain.AssemblyResolve event.
            (mono_try_assembly_resolve): renamed from try_assembly_resolve and
            made non-static.

            * assembly.c (mono_assembly_load_with_partial_name): if other       
            attempts fail, trigger the AppDomain.AssemblyResolve event handler
            to resolve the assembly.

            * domain-internals.h: added mono_try_assembly_resolve and marked
            it as internal.


svn path=/trunk/mono/; revision=85677
  • Loading branch information...
1 parent fdcf281 commit 7c50c3ceb826877c5cf781572cfe99037b98a289 @grendello grendello committed Sep 12, 2007
View
@@ -1,3 +1,18 @@
+2007-09-12 Marek Habersack <mhabersack@novell.com>
+
+ * appdomain.c (mono_runtime_init): do not install postload hooks -
+ tests show that MS.NET doesn't use anything of that sort to
+ trigger the AppDomain.AssemblyResolve event.
+ (mono_try_assembly_resolve): renamed from try_assembly_resolve and
+ made non-static.
+
+ * assembly.c (mono_assembly_load_with_partial_name): if other
+ attempts fail, trigger the AppDomain.AssemblyResolve event handler
+ to resolve the assembly.
+
+ * domain-internals.h: added mono_try_assembly_resolve and marked
+ it as internal.
+
2007-09-11 Jb Evain <jbevain@novell.com>
* object-internals.h (MonoReflectionDynamicMethod): add
View
@@ -111,8 +111,6 @@ mono_runtime_init (MonoDomain *domain, MonoThreadStartCB start_cb,
mono_install_assembly_refonly_preload_hook (mono_domain_assembly_preload, GUINT_TO_POINTER (TRUE));
mono_install_assembly_search_hook (mono_domain_assembly_search, GUINT_TO_POINTER (FALSE));
mono_install_assembly_refonly_search_hook (mono_domain_assembly_search, GUINT_TO_POINTER (TRUE));
- mono_install_assembly_postload_search_hook (mono_domain_assembly_postload_search, GUINT_TO_POINTER (FALSE));
- mono_install_assembly_postload_refonly_search_hook (mono_domain_assembly_postload_search, GUINT_TO_POINTER (TRUE));
mono_install_assembly_load_hook (mono_domain_fire_assembly_load, NULL);
mono_install_lookup_dynamic_token (mono_reflection_lookup_dynamic_token);
@@ -675,8 +673,8 @@ ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad, MonoBoolean refonly
return res;
}
-static MonoReflectionAssembly *
-try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly)
+MonoReflectionAssembly *
+mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly)
{
MonoClass *klass;
MonoMethod *method;
@@ -712,7 +710,7 @@ mono_domain_assembly_postload_search (MonoAssemblyName *aname,
aname_str = mono_stringify_assembly_name (aname);
/* FIXME: We invoke managed code here, so there is a potential for deadlocks */
- assembly = try_assembly_resolve (domain, mono_string_new (domain, aname_str), refonly);
+ assembly = mono_try_assembly_resolve (domain, mono_string_new (domain, aname_str), refonly);
g_free (aname_str);
@@ -1383,7 +1381,7 @@ ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad, MonoString *assRef,
ass = mono_assembly_load_full (&aname, NULL, &status, refOnly);
mono_assembly_name_free (&aname);
- if (!ass && (refass = try_assembly_resolve (domain, assRef, refOnly)) == NULL){
+ if (!ass && (refass = mono_try_assembly_resolve (domain, assRef, refOnly)) == NULL){
/* FIXME: it doesn't make much sense since we really don't have a filename ... */
MonoException *exc = mono_get_exception_file_not_found2 (NULL, assRef);
mono_raise_exception (exc);
View
@@ -1920,7 +1920,11 @@ mono_assembly_load_with_partial_name (const char *name, MonoImageOpenStatus *sta
if (res)
res->in_gac = TRUE;
-
+ else {
+ MonoDomain *domain = mono_domain_get ();
+ res = mono_try_assembly_resolve (domain, mono_string_new (domain, name), FALSE);
+ }
+
g_free (fullname);
mono_assembly_name_free (aname);
@@ -331,4 +331,7 @@ MonoImage *mono_assembly_open_from_bundle (const char *filename,
void
mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
+MonoReflectionAssembly *
+mono_try_assembly_resolve (MonoDomain *domain, MonoString *fname, gboolean refonly) MONO_INTERNAL;
+
#endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */
View
@@ -1,3 +1,11 @@
+2007-09-12 Marek Habersack <mhabersack@novell.com>
+
+ * assemblyresolve_event2.2.cs: added tests for assembly resolution
+ event handler.
+
+ * assemblyresolve_event.cs: added tests for assembly resolution
+ event handler.
+
2007-09-11 Mark Probst <mark.probst@gmail.com>
* coreclr-security.cs: Added positive and negative tests for
View
@@ -43,6 +43,7 @@ STRESS_TESTS_SRC= \
TEST_CS_SRC= \
array-init.cs \
arraylist.cs \
+ assemblyresolve_event.cs \
checked.cs \
char-isnumber.cs \
create-instance.cs \
@@ -281,6 +282,7 @@ TEST_IL_SRC= \
enum_types.il
TEST_CS2_SRC = \
+ assemblyresolve_event2.2.cs \
interlocked-2.2.cs \
pinvoke-2.2.cs \
bug-78431.2.cs \
@@ -0,0 +1,57 @@
+using System;
+using System.Reflection;
+
+public class App
+{
+ static bool[] expected_results = {true, false, false, true};
+ static bool handler_fired;
+
+ public static int Main ()
+ {
+ AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);
+
+ int i = 0;
+ handler_fired = false;
+
+ try {
+ Assembly.Load ("SomeAssembly");
+ } catch (Exception) {
+ }
+ if (expected_results [i] != handler_fired)
+ return 1;
+
+ i++;
+ handler_fired = false;
+ try {
+ Assembly.LoadFile ("SomeAssembly");
+ } catch (Exception) {
+ }
+ if (expected_results [i] != handler_fired)
+ return 2;
+
+ i++;
+ handler_fired = false;
+ try {
+ Assembly.LoadFrom ("SomeAssembly");
+ } catch (Exception) {
+ }
+ if (expected_results [i] != handler_fired)
+ return 3;
+
+ i++;
+ handler_fired = false;
+ try {
+ Assembly.LoadWithPartialName ("SomeAssembly");
+ } catch (Exception) {
+ }
+ if (expected_results [i] != handler_fired)
+ return 4;
+
+ return 0;
+ }
+
+ static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) {
+ handler_fired = true;
+ return null;
+ }
+}
@@ -0,0 +1,39 @@
+using System;
+using System.Reflection;
+
+public class App
+{
+ static bool[] expected_results = {false, false};
+ static bool handler_fired;
+
+ public static int Main ()
+ {
+ AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(MyReflectionResolveEventHandler);
+
+ int i = 0;
+ handler_fired = false;
+
+ try {
+ Assembly.ReflectionOnlyLoad ("SomeAssembly");
+ } catch (Exception) {
+ }
+ if (expected_results [i] != handler_fired)
+ return 1;
+
+ i++;
+ handler_fired = false;
+ try {
+ Assembly.ReflectionOnlyLoadFrom ("SomeAssembly");
+ } catch (Exception) {
+ }
+ if (expected_results [i] != handler_fired)
+ return 2;
+
+ return 0;
+ }
+
+ static Assembly MyReflectionResolveEventHandler(object sender, ResolveEventArgs args) {
+ handler_fired = true;
+ return null;
+ }
+}

0 comments on commit 7c50c3c

Please sign in to comment.