[tests] Don't use AppDomain.AppendPrivateBinPath for assembly-load-remap.exe
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 16 Mar 2016 02:33:24 +0000 (03:33 +0100)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 16 Mar 2016 02:33:24 +0000 (03:33 +0100)
It's not supposed to contain a full path to a directory, but rather a relative path
to a subdirectory of the ApplicationBase. However, this isn't enforced in all cases
by Mono so setting a full path worked when the path doesn't contain a '.' because then
the code in [1] doesn't clear the variable and the path is added to the domain->search_path.

This caused the test to fail on Wrench on the mono-4.4.0 lane because the path contains
a dot while confusingly it worked fine on master.

Fixing this by appending the xbuild_14 path via an alternative (albeit slightly hacky)
method related to the standard MONO_PATH env var. Because the variable is only read
once at app startup we need to call into the runtime to explicitly set the new path
before trying to load the MSBuild 14 assemblies. This is fine since we only
want to test that the correct assembly version is loaded and nothing else.

[1] https://github.com/mono/mono/blob/37b2b9fbc25a2199aba1d794117924d4828360a7/mono/metadata/appdomain.c#L1319-L1337

mono/tests/assembly-load-remap.cs

index f9c93d5da88f65186082c68cd3dc8b432ff2c562..566e98ce085ba7e56e40ed70c569c73233977126 100644 (file)
@@ -1,9 +1,13 @@
 using System;
 using System.IO;
 using System.Reflection;
+using System.Runtime.InteropServices;
 
 public class Tests
 {
+       [DllImport("__Internal")]
+       extern static void mono_set_assemblies_path (string path);
+
        public static void Main (string[] args)
        {
                var ver40 = new Version (4, 0, 0, 0);
@@ -17,11 +21,13 @@ public class Tests
                var frwk20 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
                var frwk35 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
 
-               // when run as part of the test suite, we need to register the xbuild 14.0 path or v14 assembly lookup will fail 
-               if (!String.IsNullOrEmpty (Environment.GetEnvironmentVariable ("MONO_PATH"))) {
-                       var p = Path.Combine (new DirectoryInfo (Environment.GetEnvironmentVariable ("MONO_PATH")).Parent.FullName, "xbuild_14");
-                       Console.WriteLine("Adding private bin path " + p);
-                       AppDomain.CurrentDomain.AppendPrivatePath (p);
+               // when run as part of the test suite, we need to register the xbuild 14.0 path or v14 assembly lookup will fail
+               var mono_path = Environment.GetEnvironmentVariable ("MONO_PATH");
+               if (!String.IsNullOrEmpty (mono_path)) {
+                       var xbuild = Path.Combine (new DirectoryInfo (mono_path).Parent.FullName, "xbuild_14");
+                       mono_path = xbuild + Path.PathSeparator + mono_path;
+                       Console.WriteLine ("Setting Mono assemblies path to " + mono_path);
+                       mono_set_assemblies_path (mono_path);
                }
 
                var engn140 = Assembly.ReflectionOnlyLoad ("Microsoft.Build.Engine, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");