[bcl] Invoke assembly resolve hooks even if the assembly name has a parse error....
authorZoltan Varga <vargaz@gmail.com>
Fri, 6 Dec 2013 18:39:53 +0000 (19:39 +0100)
committerZoltan Varga <vargaz@gmail.com>
Fri, 6 Dec 2013 18:40:05 +0000 (19:40 +0100)
mcs/class/corlib/Test/System/AppDomainTest.cs
mono/metadata/appdomain.c

index 1d88666538f50e9ec25e0f6acd9a61fd6a1d4ac3..9c950226391ce42bf60a5e48f7c724be13bab6ba 100644 (file)
@@ -2073,7 +2073,6 @@ namespace MonoTests.System
                                AppDomain.CurrentDomain.ExecuteAssembly (
                                        assembly.Location);
                                Assert.Fail ("#1");
-#if NET_2_0
                        } catch (MissingMethodException ex) {
                                // Entry point not found in assembly '...'
                                Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
@@ -2081,15 +2080,6 @@ namespace MonoTests.System
                                Assert.IsNotNull (ex.Message, "#4");
                                Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
                        }
-#else
-                       } catch (COMException ex) {
-                               // Unspecified error
-                               Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
-                               Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
-                               Assert.IsNull (ex.InnerException, "#4");
-                               Assert.IsNotNull (ex.Message, "#5");
-                       }
-#endif
                }
 
                [Test] // ExecuteAssembly (String, Evidence)
@@ -2102,7 +2092,6 @@ namespace MonoTests.System
                                        assembly.Location,
                                        (Evidence) null);
                                Assert.Fail ("#1");
-#if NET_2_0
                        } catch (MissingMethodException ex) {
                                // Entry point not found in assembly '...'
                                Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
@@ -2110,15 +2099,6 @@ namespace MonoTests.System
                                Assert.IsNotNull (ex.Message, "#4");
                                Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
                        }
-#else
-                       } catch (COMException ex) {
-                               // Unspecified error
-                               Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
-                               Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
-                               Assert.IsNull (ex.InnerException, "#4");
-                               Assert.IsNotNull (ex.Message, "#5");
-                       }
-#endif
                }
 
                [Test] // ExecuteAssembly (String, Evidence, String [])
@@ -2132,7 +2112,6 @@ namespace MonoTests.System
                                        (Evidence) null,
                                        new string [0]);
                                Assert.Fail ("#1");
-#if NET_2_0
                        } catch (MissingMethodException ex) {
                                // Entry point not found in assembly '...'
                                Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
@@ -2140,15 +2119,6 @@ namespace MonoTests.System
                                Assert.IsNotNull (ex.Message, "#4");
                                Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
                        }
-#else
-                       } catch (COMException ex) {
-                               // Unspecified error
-                               Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
-                               Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
-                               Assert.IsNull (ex.InnerException, "#4");
-                               Assert.IsNotNull (ex.Message, "#5");
-                       }
-#endif
                }
 
                [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm)
@@ -2165,7 +2135,6 @@ namespace MonoTests.System
                                        (byte []) null,
                                        AssemblyHashAlgorithm.SHA1);
                                Assert.Fail ("#1");
-#if NET_2_0
                        } catch (MissingMethodException ex) {
                                // Entry point not found in assembly '...'
                                Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2");
@@ -2173,15 +2142,6 @@ namespace MonoTests.System
                                Assert.IsNotNull (ex.Message, "#4");
                                Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5");
                        }
-#else
-                       } catch (COMException ex) {
-                               // Unspecified error
-                               Assert.AreEqual (typeof (COMException), ex.GetType (), "#2");
-                               Assert.AreEqual (-2147467259, ex.ErrorCode, "#3");
-                               Assert.IsNull (ex.InnerException, "#4");
-                               Assert.IsNotNull (ex.Message, "#5");
-                       }
-#endif
                }
 
                [Test] // bug #79720
@@ -3044,14 +3004,9 @@ namespace MonoTests.System
                        try {
                                AppDomain.CurrentDomain.Load (aname);
                                Assert.Fail ("#C9");
-#if NET_2_0
                        } catch (SecurityException) {
                                // Invalid assembly public key
                        }
-#else
-                       } catch (FileLoadException) {
-                       }
-#endif
 
                        aname = new AssemblyName ();
                        aname.Name = "bug79522C";
@@ -3212,6 +3167,30 @@ namespace MonoTests.System
                        // we have no public way to get the default appdomain
                }
 
+               static bool resolve_called;
+
+               [Test]
+               public void AssemblyResolveParseError ()
+               {
+                       AppDomain currentDomain = AppDomain.CurrentDomain;
+                       ResolveEventHandler d = ParseErrorResolve;
+                       currentDomain.AssemblyResolve += d;
+                       try {
+                               resolve_called = false;
+                               var a = Assembly.Load ("MyDynamicType, 1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756");
+                               Assert.Fail ();
+                       } catch (FileNotFoundException) {
+                               Assert.IsTrue (resolve_called);
+                       }
+                       currentDomain.AssemblyResolve -= d;
+               }
+
+               static Assembly ParseErrorResolve (object sender, ResolveEventArgs args)
+               {
+                       resolve_called = true;
+                       return null;
+               }
+
                [Test]
                public void ReflectionOnlyGetAssemblies ()
                {
index ad186f50707741b82f3e863e31037a41d0cfbdf4..f5090c04508675cbe7b7d91966ed9ea823d1446a 100644 (file)
@@ -1944,7 +1944,9 @@ ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,  MonoString *assRef,
 
        if (!parsed) {
                /* This is a parse error... */
-               return NULL;
+               if (!refOnly)
+                       refass = mono_try_assembly_resolve (domain, assRef, refOnly);
+               return refass;
        }
 
        ass = mono_assembly_load_full_nosearch (&aname, NULL, &status, refOnly);