Exemple #1
0
    private Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
    {
        var name = new AssemblyName(args.Name).Name;

        var searchPaths = new[] {
            "",
            Path.Combine(name, "bin", "net45")
        };

        var basePath = _originalApplicationBase ?? AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

        foreach (var searchPath in searchPaths)
        {
            var path = Path.Combine(basePath,
                                    searchPath,
                                    name + ".dll");

            if (File.Exists(path))
            {
                return Assembly.LoadFile(path);
            }
        }

        return null;
    }
    public static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
    {
        var name = new AssemblyName(args.Name).Name.ToLowerInvariant();
        var existingAssembly = ReadExistingAssembly(name);
        if (existingAssembly != null)
        {
            return existingAssembly;
        }

        var prefix = string.Concat("costura.", name);
        var executingAssembly = Assembly.GetExecutingAssembly();

        byte[] assemblyData;
        using (var assemblyStream = GetAssemblyStream(executingAssembly, prefix))
        {
            if (assemblyStream == null)
            {
                return null;
            }
            assemblyData = ReadStream(assemblyStream);
        }

        using (var pdbStream = GetDebugStream(executingAssembly, prefix))
        {
            if (pdbStream != null)
            {
                var pdbData = ReadStream(pdbStream);
                return Assembly.Load(assemblyData, pdbData);
            }
        }

        return Assembly.Load(assemblyData);
    }
    private rf.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        var satelliteAssembly = moduleWeaver.ModuleDefinition.AssemblyResolver.Resolve(args.Name);
        moduleWeaver.LogInfo(String.Format("---| Resolving assembly  [{0}] on behalf of [{1}]",args.Name,args.RequestingAssembly));
        moduleWeaver.LogInfo(String.Format("---| Weavers FQAN [{0}] resolved at [{1}]", moduleWeaver.ModuleDefinition.FullyQualifiedName,satelliteAssembly.FullName));
        moduleWeaver.LogInfo(String.Format("---| satelliteAssembly name [{0}] with argsname[{1}]", satelliteAssembly.Name, args.Name));

        foreach (var reff in moduleWeaver.ReferenceCopyLocalPaths)
        {
            moduleWeaver.LogInfo(String.Format("---|-- referenced module:[{0}] ", new FileInfo(reff).Name));
        }

        var referenceFiles = moduleWeaver.ReferenceCopyLocalPaths
            .Select(p => new FileInfo(p))
            .ToList<FileInfo>();

        var assemblyFile = referenceFiles
                                .Where(rf => rf.Name.Split('.').Count()>0 &&
                                                rf.Name.Split('.')[0]==( (args.Name.Split(',')[0])))
                                .FirstOrDefault();
        moduleWeaver.LogInfo(String.Format("---|-- RESOLVED: assembly file to load:[{0}] ", assemblyFile?.FullName));

        if (assemblyFile != null)
        {
            return rf.Assembly.ReflectionOnlyLoadFrom(assemblyFile.FullName);
        }
        else
        {
            moduleWeaver.LogErrorPoint(String.Format("---| Assembly file not found {0} at {1}", referenceFiles[0], args.Name.Split(',')[0]), new SequencePoint(new Document("")));
        }
        return null;
    }
 private static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
 {
     if (args.Name.StartsWith("Microsoft.Ink"))
         return latestInk;
     else
         return null;
 }
Exemple #5
0
	static Assembly CurrentDomain_AssemblyResolve (object sender, ResolveEventArgs args)
	{
		lock (_syncLock) {
			_AssemblyResolves.Add (args.Name);
		}
		return null;
	}
		private static Assembly OnTypeResolve(object sender, ResolveEventArgs args)
		{
			TypeWrapper type;
#if CLASSGC
			DynamicClassLoader instance;
			ClassLoaderWrapper loader = ClassLoaderWrapper.GetClassLoaderForDynamicJavaAssembly(args.RequestingAssembly);
			if(loader == null)
			{
				return null;
			}
			instance = (DynamicClassLoader)loader.GetTypeWrapperFactory();
#endif
			instance.dynamicTypes.TryGetValue(args.Name, out type);
			if(type == null)
			{
				return null;
			}
			try
			{
				type.Finish();
			}
			catch(RetargetableJavaException x)
			{
				throw x.ToJava();
			}
			// NOTE We used to remove the type from the hashtable here, but that creates a race condition if
			// another thread also fires the OnTypeResolve event while we're baking the type.
			// I really would like to remove the type from the hashtable, but at the moment I don't see
			// any way of doing that that wouldn't cause this race condition.
			// UPDATE since we now also use the dynamicTypes hashtable to keep track of type names that
			// have been used already, we cannot remove the keys.
			return type.TypeAsTBD.Assembly;
		}
 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     if (args.Name.StartsWith("NServiceBus.Core,"))
     {
         return typeof(IMessage).Assembly;
     }
     return null;
 }
Exemple #8
0
 private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
 {
     string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     var name = new AssemblyName(args.Name).Name;
     var path = Path.Combine(dir, name + ".dll");
     Assembly assembly = Assembly.LoadFile(path);
     return assembly;
 }
Exemple #9
0
	static Assembly AppDomain_AssemblyResolve (object sender, ResolveEventArgs args)
	{
		foreach (AssemblyBuilder ab in _assemblyBuilders) {
			if (args.Name.StartsWith (ab.GetName ().Name))
				return ab;
		}
		return null;
	}
Exemple #10
0
	static Assembly AppDomain_ReflectionOnlyAssemblyResolve (object sender, ResolveEventArgs args)
	{
		switch (args.Name) {
		case "A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null":
			return Assembly.ReflectionOnlyLoadFrom (Assembly.GetExecutingAssembly ().Location);
		default:
			return null;
		}
	}
Exemple #11
0
	static Assembly AppDomain_AssemblyResolve (object sender, ResolveEventArgs args)
	{
		switch (args.Name) {
		case "A, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null":
			return typeof (int).Assembly;
		default:
			return null;
		}
	}
	static Assembly MyResolveEventHandler (object sender, ResolveEventArgs args)
	{
		event_handler_count++;
		Console.WriteLine ("Resolve assembly: {0}", args.Name);
		if (args.Name == "test, Version=0.0.0.0, Culture=neutral" || args.Name == "test, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
			return Assembly.LoadFile (String.Format ("{0}{1}assemblyresolve{1}deps{1}test.dll", Directory.GetCurrentDirectory (), Path.DirectorySeparatorChar));
		if (args.Name == "TestBase, Version=0.0.0.0, Culture=neutral" || args.Name == "TestBase, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
			return Assembly.LoadFile (String.Format ("{0}{1}assemblyresolve{1}deps{1}TestBase.dll", Directory.GetCurrentDirectory (), Path.DirectorySeparatorChar));
		return null;
	}
	static Assembly MyResolveEventHandler (object sender, ResolveEventArgs args)
	{
		var path = Path.Combine (Directory.GetCurrentDirectory (), "assemblyresolve", "deps");
		if (args.Name == "test" && args.RequestingAssembly == null)
			return Assembly.LoadFile (Path.Combine (path, "test.dll"));
		if (args.Name == "TestBase, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" && args.RequestingAssembly.GetName ().Name == "test")
			return Assembly.LoadFile (Path.Combine (path, "TestBase.dll"));

		throw new InvalidOperationException (String.Format ("Unexpected parameter combination {0} {1}", args.Name, args.RequestingAssembly));
	}
 static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     if (ProviderPath != null && File.Exists(ProviderPath))
     {
         string name = Path.GetFileNameWithoutExtension(ProviderPath);
         if (args.Name.StartsWith(name))
             return Assembly.LoadFrom(ProviderPath);
     }
     return null;
 }
 public Assembly AssemblyResolve(object sender, ResolveEventArgs args)
 {
     char[] separator = new char[] { ',' };
     string path = Path.Combine(this._assemblyDirectory, args.Name.Split(separator)[0] + ".dll");
     if (File.Exists(path))
     {
         return Assembly.LoadFrom(path);
     }
     return null;
 }
Exemple #16
0
    static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
    {
        string assembly_name = args.Name.Split(',')[0] + ".dll";

        //		Console.WriteLine("Load assembly dynamically: {0}", assembly_name);

        string path = System.IO.Path.Combine(GetPathToExecutable(), dll_path);
        string assembly_fp = System.IO.Path.Combine(path, assembly_name);
        Assembly assembly = Assembly.LoadFrom(assembly_fp);
        return assembly;
    }
    static Assembly MyReflectionResolveEventHandler(object
sender,
ResolveEventArgs
args)
    {
        handler_fired
        =
        true;
        return
        null;
    }
 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         if (assembly.FullName == args.Name)
         {
             return assembly;
         }
     }
     return null;
 }
 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         if (string.Equals(assembly.FullName, args.Name, StringComparison.OrdinalIgnoreCase))
         {
             return assembly;
         }
     }
     return null;
 }
    static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        Assembly result = null;
        Dictionary<string, Assembly> requesting;
        if (referencedAssemblies.TryGetValue(args.RequestingAssembly.FullName, out requesting))
        {
            requesting.TryGetValue(args.Name, out result);
        }

        return result;
    }
Exemple #21
0
	static Assembly AppDomain_ReflectionOnlyAssemblyResolve (object sender, ResolveEventArgs args)
	{
		reflection_assembly_resolve_level++;

		switch (reflection_assembly_resolve_level) {
		case 1:
			return null;
		case 2:
			return Assembly.ReflectionOnlyLoadFrom (Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "B_org.dll"));
		default:
			return null;
		}
	}
    Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {


        if (args.Name.Contains("mscorlib.Extensions"))
        {
            var codeBase = GetType().Assembly.CodeBase;
            codeBase = codeBase.Substring(8, codeBase.Length - 8);
            var directoryName = Path.GetDirectoryName(codeBase);
            var combine =Path.GetFullPath( Path.Combine(directoryName, @"..\..\..\tools\WindowsPhone\mscorlib.Extensions.dll"));
            return Assembly.LoadFrom(combine);
        }
        return null;
    }
Exemple #23
0
    //!!! for load embedded dll: (2) implement this handler
    System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        string dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", "");

        dllName = dllName.Replace(".", "_");

        if (dllName.EndsWith("_resources")) return null;

        System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());

        byte[] bytes = (byte[])rm.GetObject(dllName);

        return System.Reflection.Assembly.Load(bytes);
    }
Exemple #24
0
        private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            if (new AssemblyName(args.Name).Name == "EntityFramework")
            {
                var assemblyPath = Path.Combine(
                    AppDomain.CurrentDomain.BaseDirectory, @"..\lib\net45\EntityFramework.dll");

                if (File.Exists(assemblyPath))
                {
                    return Assembly.LoadFrom(assemblyPath);
                }
            }

            return null;
        }
Exemple #25
0
	static Assembly AppDomain_AssemblyResolve (object sender, ResolveEventArgs args)
	{
		assembly_resolve_level++;

		switch (assembly_resolve_level) {
		case 1:
			return Assembly.Load ("abc");
		case 2:
			return null;
		case 3:
			return typeof (int).Assembly;
		case 4:
			return typeof (XmlDocument).Assembly;
		default:
			return typeof (Uri).Assembly;
		}
	}
Exemple #26
0
		public Assembly ResolveAssembly (Object sender, ResolveEventArgs args)
		{
			// find assembly in probe paths
			foreach (string path in _probePaths) {
				string[] assemblies = Directory.GetFiles (path, "*.dll");
				foreach (string assemblyFile in assemblies) {
					try {
						AssemblyName assemblyName = AssemblyName.GetAssemblyName (assemblyFile);
						if (assemblyName.FullName == args.Name) {
							return Assembly.LoadFrom (assemblyFile);
						}
					} catch { }
				}
			}

			// assembly reference could not be resolved
			return null;
		}
            public static Assembly AssemblyResolve(object sender, ResolveEventArgs e)
            {
                var dll = e.Name.Replace("\\\\", "\\");

                if (dll.ToLower().Contains("inthehand.net.personal"))
                        Extract(Files.InTheHandManaged | Files.InTheHandNative);
                    else if (dll.ToLower().Contains("vlc"))
                        Extract(Files.VLC);
                else
                    return null;
                    try
                    {
                        var asm = Assembly.Load(dll);
                        return asm;
                    }
                    catch { }
                    return null;
            }
    public static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
    {
        var name = new AssemblyName(args.Name).Name.ToLowerInvariant();
        var existingAssembly = ReadExistingAssembly(name);
        if (existingAssembly != null)
        {
            return existingAssembly;
        }

        var prefix = string.Concat("costura.", name);

        var assemblyTempFilePath = Path.Combine(tempBasePath, string.Concat(prefix,".dll"));
        if (File.Exists(assemblyTempFilePath))
        {
            return Assembly.LoadFile(assemblyTempFilePath);
        }

        var executingAssembly = Assembly.GetExecutingAssembly();

        using (var assemblyStream = GetAssemblyStream(executingAssembly, prefix))
        {
            if (assemblyStream == null)
            {
                return null;
            }
            var assemblyData = ReadStream(assemblyStream);
            File.WriteAllBytes(assemblyTempFilePath, assemblyData);
        }

        using (var pdbStream = GetDebugStream(executingAssembly, prefix))
        {
            if (pdbStream != null)
            {
                var pdbData = ReadStream(pdbStream);
                var pdbTempFilePath = Path.Combine(tempBasePath, string.Concat(prefix, ".pdb"));
                var assemblyPdbTempFilePath = Path.Combine(tempBasePath, pdbTempFilePath);
                File.WriteAllBytes(assemblyPdbTempFilePath, pdbData);
            }
        }
        return Assembly.LoadFile(assemblyTempFilePath);
    }
    private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
    {
        Assembly executingAssembly = Assembly.GetExecutingAssembly();
        AssemblyName assemblyName = new AssemblyName(args.Name);

        string path = assemblyName.Name + ".dll";
        if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
        {
            path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
        }

        using (Stream stream = executingAssembly.GetManifestResourceStream(path))
        {
            if (stream == null)
                return null;

            byte[] assemblyRawBytes = new byte[stream.Length];
            stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
            return Assembly.Load(assemblyRawBytes);
        }
    }
    private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
    {
        if (!_initialized)
        {
            _initialized = true;

            var embeddedAssemblies = Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(name => name.EndsWith(".dll")).ToList();
            foreach (var embeddedAssembly in embeddedAssemblies)
            {
                var assemblyData = ReadMatchingResourceByteArray(embeddedAssembly);
                var pdbData = ReadMatchingResourceByteArray(embeddedAssembly.Replace(".dll", ".pdb"));

                if (!IsLoaded(assemblyData))
                {
                    Assembly.Load(assemblyData, pdbData);
                }
            }
        }

        return AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly => assembly.FullName == args.Name);
    }
        private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (args.Name.Contains(".resources"))
            {
                return(null);
            }

            int nPos = args.Name.IndexOf(',');

            if (nPos >= 0)
            {
                string strName = args.Name.Substring(0, nPos) + ".dll";
                string strPath = m_fiPath.DirectoryName + "\\" + strName;

                Trace.WriteLine("Loading '" + strPath + "'.");

                return(Assembly.LoadFile(strPath));
            }

            return(null);
        }
        private Assembly AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var assemblyPath = Path.Combine(Directory.GetCurrentDirectory(), output, args.Name.Split(',')[0] + ".dll");

            return(File.Exists(assemblyPath) ? Assembly.LoadFile(assemblyPath) : null);
        }
Exemple #33
0
 private static Assembly Resolve(ResolveEventArgs args, IEnumerable <string> directories)
 {
     return(directories
            .Select(d => Resolve(args, d))
            .FirstOrDefault());
 }
Exemple #34
0
        private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(e => e.FullName.Contains("XComponent.Functions.Core"));

            return(assembly);
        }
Exemple #35
0
 private static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
 {
     Console.WriteLine("Resolving...");
     return(typeof(MyType).Assembly);
 }
 /// <summary>
 /// This is an assembly resolution handler necessary for fixing up types instantiated in different
 /// AppDomains and loaded with a Assembly.LoadFrom equivalent call. See comments in TaskEngine.ExecuteTask
 /// for more details.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 internal Assembly ResolveAssembly(object sender, ResolveEventArgs args)
 private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
 {
     return(Assembly.LoadFrom(args.Name));
 }
Exemple #38
0
 static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     return(EmbeddedAssembly.Get(args.Name));
 }
Exemple #39
0
 private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
 {
     return(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName == args.Name));
 }
 /// <summary>
 /// Hendler for AssemblyResolve event
 /// Run this line of code to use this utility (as earlier as possible, recommended in App's constructor)
 ///     AppDomain.CurrentDomain.AssemblyResolve += ResourceAssemblyUtil.AssemblyResolveHandler;
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 /// <returns></returns>
 public static Assembly AssemblyResolveHandler(object sender, ResolveEventArgs args)
 {
     return(LoadResourceAssembly(args.Name));
 }
Exemple #41
0
        private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            Assembly     executingAssembly = Assembly.GetExecutingAssembly();
            AssemblyName assemblyName      = new AssemblyName(args.Name);

            var path = assemblyName.Name + ".dll";

            //判断程序集的区域性
            if (!assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture))
            {
                path = string.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
            }

            using (Stream stream = executingAssembly.GetManifestResourceStream(path))
            {
                if (stream == null)
                {
                    return(null);
                }

                var assemblyRawBytes = new byte[stream.Length];
                stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
                return(Assembly.Load(assemblyRawBytes));
            }
        }
Exemple #42
0
 /// <summary>
 /// Handles the AssemblyResolve event of the CurrentDomain control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="args">The <see cref="ResolveEventArgs"/> instance containing the event data.</param>
 /// <returns>Manually resolved assembly, or null.</returns>
 private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     return(LoadedAssembliesResolver.Instance.GetAssembly(args.Name));
 }
Exemple #43
0
 System.Reflection.Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     Autodesk.REX.Framework.REXConfiguration.Initialize(System.Reflection.Assembly.GetExecutingAssembly());
     return(Autodesk.REX.Framework.REXAssemblies.Resolve(sender, args, "2016", System.Reflection.Assembly.GetExecutingAssembly()));
 }
 internal static System.Reflection.Assembly ResolveReflectionAssemblyDependency(object sender, ResolveEventArgs args)
 {
     return(ReflectionOnlyLoad(args.Name));
 }
Exemple #45
0
        /// <summary>
        /// This resolver is used to ensure that we can cast the test runner's transparent proxy to IGallioTestRunner.
        /// </summary>
        /// <remarks>
        /// <para>
        /// TestDriven.Net initially loaded this assembly using Assembly.LoadFrom.  When the cast occurs, the runtime implicitly
        /// tries to load the interface using Assembly.Load by fullname which does not normally consider anything loaded with LoadFrom.
        /// So we introduce a resolver that recognizes when we are attempting to load this assembly by fullname and
        /// just returns it.  Without it, an InvalidCastException will occur.
        /// </para>
        /// </remarks>
        private static Assembly ResolveRunnerAssembly(object sender, ResolveEventArgs e)
        {
            Assembly runnerAssembly = typeof(LocalProxyTestRunner).Assembly;

            return(e.Name == runnerAssembly.FullName ? runnerAssembly : null);
        }
Exemple #46
0
        private static Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
        {
            var a = Assembly.ReflectionOnlyLoadFrom(Path.Combine(Environment.CurrentDirectory, new AssemblyName(args.Name).Name + ".dll"));

            return(a);
        }
Exemple #47
0
 private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     return(ass);
 }
        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            System.Reflection.AssemblyName name = new System.Reflection.AssemblyName(args.Name);
            if (name.Name.ToLowerInvariant().EndsWith(".resources"))
            {
                return(null);
            }
            string installPath = HpToolsLauncher.Helper.getLRInstallPath();

            if (installPath == null)
            {
                log(Resources.CannotLocateInstallDir);
                Environment.Exit((int)Launcher.ExitCodeEnum.Aborted);
            }
            //log(Path.Combine(installPath, "bin", name.Name + ".dll"));
            return(System.Reflection.Assembly.LoadFrom(Path.Combine(installPath, "bin", name.Name + ".dll")));
        }
        public static Assembly Resolve(IReadOnlyDictionary <string, string> knownAssemblies, object s, ResolveEventArgs e)
        {
            var requiredAssembly = new AssemblyName(e.Name);
            var assembly         = AppDomain.CurrentDomain
                                   .GetAssemblies()
                                   .FirstOrDefault(x => new AssemblyName(x.FullName).Name == requiredAssembly.Name);

            if (assembly != null)
            {
                return(assembly);
            }

            var binding = knownAssemblies.SingleOrDefault(x => x.Key.StartsWith(e.Name.Split(',')[0]));

            return(binding.Value != null?Assembly.LoadFile(binding.Value) : null);
        }
Exemple #50
0
        /// <summary>
        /// 启动所有dll资源文件
        /// </summary>
        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            string dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", "");

            dllName = dllName.Replace(".", "_");
            if (dllName.EndsWith("_resources"))
            {
                return(null);
            }
            System.Resources.ResourceManager rm = new System.Resources.ResourceManager("doubi.Resources", System.Reflection.Assembly.GetExecutingAssembly());
            byte[] bytes = (byte[])rm.GetObject(dllName);
            return(System.Reflection.Assembly.Load(bytes));
        }
Exemple #51
0
        static System.Reflection.Assembly DefaultDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            //args.Name -> "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

            string asmName             = args.Name.Split(',').First() + ".dll";
            string wixSharpAsmLocation = IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            string potentialAsm = IO.Path.Combine(wixSharpAsmLocation, asmName);

            if (IO.File.Exists(potentialAsm))
            {
                try
                {
                    return(System.Reflection.Assembly.LoadFrom(potentialAsm));
                }
                catch { }
            }

            return(null);
        }
Exemple #52
0
        private static System.Reflection.Assembly MyResolveEventHandler(object sender, ResolveEventArgs args)
        {
            string strTempAssmbPath = "";
            string neededAssembly   = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";

            System.Reflection.Assembly objExecutingAssemblies = System.Reflection.Assembly.GetExecutingAssembly();

            foreach (System.Reflection.AssemblyName strAssmbName in objExecutingAssemblies.GetReferencedAssemblies())
            {
                string currentAssembly = strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) + ".dll";

                if (currentAssembly == neededAssembly)
                {
                    strTempAssmbPath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll");

                    if (!System.IO.File.Exists(strTempAssmbPath)) // we are in the case of QSF as exe, so the Path is different
                    {
                        strTempAssmbPath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "..\\..\\..\\..\\bin\\ReleaseTrial\\");
                        strTempAssmbPath = System.IO.Path.Combine(strTempAssmbPath, neededAssembly);
                    }
                    break;
                }
            }

            System.Reflection.Assembly myAssembly = null;

            if (!string.IsNullOrEmpty(strTempAssmbPath))
            {
                myAssembly = System.Reflection.Assembly.LoadFrom(strTempAssmbPath);
            }
            return(myAssembly);
        }
Exemple #53
0
 private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
 {
     System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
     for (int i = 0; i < assemblies.Length; i++)
     {
         if (assemblies[i].FullName == args.Name)
         {
             return(assemblies[i]);
         }
     }
     return(null);
 }
Exemple #54
0
        private static Assembly AssemblyResolve_ManagedProfilerDependencies(object sender, ResolveEventArgs args)
        {
            var assemblyName = new AssemblyName(args.Name);

            // On .NET Framework, having a non-US locale can cause mscorlib
            // to enter the AssemblyResolve event when searching for resources
            // in its satellite assemblies. This seems to have been fixed in
            // .NET Core in the 2.0 servicing branch, so we should not see this
            // occur, but guard against it anyways. If we do see it, exit early
            // so we don't cause infinite recursion.
            if (string.Equals(assemblyName.Name, "System.Private.CoreLib.resources", StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            var path = Path.Combine(ManagedProfilerDirectory, $"{assemblyName.Name}.dll");

            if (assemblyName.Name.StartsWith("Datadog.Trace", StringComparison.OrdinalIgnoreCase) &&
                assemblyName.FullName.IndexOf("PublicKeyToken=def86d061d0d2eeb", StringComparison.OrdinalIgnoreCase) >= 0 &&
                File.Exists(path))
            {
                return(Assembly.LoadFrom(path)); // Load the main profiler and tracer into the default Assembly Load Context
            }
            else if (File.Exists(path))
            {
                return(DependencyLoadContext.LoadFromAssemblyPath(path)); // Load unresolved framework and third-party dependencies into a custom Assembly Load Context
            }

            return(null);
        }
Exemple #55
0
        private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
        {
            string name;

            byte[]   assemblyBytes;
            Assembly loadedAssembly = null;

            AssemblyName assemblyName = new AssemblyName(args.Name);
            CultureInfo  cultureInfo  = assemblyName.CultureInfo;

            name = assemblyName.Name.ToUpperInvariant();

            if (name == "EXCELDNA")             /* Special case for pre-0.14 versions of ExcelDna */
            {
                name = "EXCELDNA.INTEGRATION";
            }

            if (name == "EXCELDNA.LOADER")
            {
                // Loader must have been loaded from bytes.
                // But I have seen the Loader, and it is us.
                return(Assembly.GetExecutingAssembly());
            }

            bool isResourceAssembly = name.EndsWith(".RESOURCES");

            // This check and mapping must match that done when packing (in ResourceHelper.cs : ResourceUpdate.AddAssembly)
            if (isResourceAssembly && cultureInfo != null && !string.IsNullOrEmpty(cultureInfo.Name))
            {
                name += "." + cultureInfo.Name.ToUpperInvariant();
            }

            // Check our AssemblyResolve cache
            if (loadedAssemblies.TryGetValue(name, out loadedAssembly))
            {
                return(loadedAssembly);
            }

            // Check if it is loaded in the AppDomain already,
            // e.g. from resources as an ExternalLibrary
            loadedAssembly = GetAssemblyIfLoaded(assemblyName);
            if (loadedAssembly != null)
            {
                Logger.Initialization.Info("Assembly {0} was found to already be loaded into the AppDomain.", name);
                loadedAssemblies[name] = loadedAssembly;
                return(loadedAssembly);
            }

            // Now check in resources ...
            // We expect failures when loading .resources assemblies, so only log at the Verbose level.
            // From: http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx
            // "Note: Unless you are explicitly debugging the failure of a resource to load,
            //        you will likely want to ignore failures to find assemblies with the ".resources" extension
            //        with the culture set to something other than "neutral". Those are expected failures when the
            //        ResourceManager is probing for satellite assemblies."

            if (isResourceAssembly)
            {
                Logger.Initialization.Verbose("Attempting to load {0} from resources.", name);
            }
            else
            {
                Logger.Initialization.Info("Attempting to load {0} from resources.", name);
            }

            assemblyBytes = GetResourceBytes(name, 0);
            if (assemblyBytes == null)
            {
                if (isResourceAssembly)
                {
                    Logger.Initialization.Verbose("Assembly {0} could not be loaded from resources (ResourceManager probing for satellite assemblies).", name);
                }
                else
                {
                    Logger.Initialization.Warn("Assembly {0} could not be loaded from resources.", name);
                }
                return(null);
            }

            byte[] pdbBytes = GetResourceBytes(name, 4);
            if (pdbBytes != null)
            {
                Logger.Initialization.Info("Trying Assembly.Load for {0} (from {1} bytes, with {2} bytes of pdb).", name, assemblyBytes.Length, pdbBytes.Length);
            }
            else
            {
                Logger.Initialization.Info("Trying Assembly.Load for {0} (from {1} bytes, without pdb).", name, assemblyBytes.Length);
            }
            try
            {
                loadedAssembly = pdbBytes == null?Assembly.Load(assemblyBytes) : Assembly.Load(assemblyBytes, pdbBytes);

                loadedAssemblies[name] = loadedAssembly;
                return(loadedAssembly);
            }
            catch (Exception e)
            {
                Logger.Initialization.Error(e, "Error during Assembly Load from bytes");
            }
            return(null);
        }
Exemple #56
0
        /// <summary>
        /// Resolves assemblies in lib.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            var probingPath = AppDomain.CurrentDomain.BaseDirectory + @"lib";
            var assyName    = new AssemblyName(args.Name);

            var newPath    = Path.Combine(probingPath, assyName.Name);
            var searchPath = newPath;

            if (!searchPath.EndsWith(".dll"))
            {
                searchPath = searchPath + ".dll";
            }
            if (File.Exists(searchPath))
            {
                var assy = Assembly.LoadFile(searchPath);
                return(assy);
            }
            //look for exe assembly (CSharpImageLibrary)
            searchPath = newPath;
            if (!searchPath.EndsWith(".exe"))
            {
                searchPath = searchPath + ".exe";
            }
            if (File.Exists(searchPath))
            {
                var assy = Assembly.LoadFile(searchPath);
                return(assy);
            }
            return(null);
        }
Exemple #57
0
 public Assembly ResolveResEventHandler(object sender, ResolveEventArgs args)
 {
     return(Assembly.LoadFrom(this.asmFile));
 }
Exemple #58
0
        /// <summary>
        /// This is necessary on Windows because without it, even though the assemblies are already loaded
        /// the CLR will still throw FileNotFoundException (unable to load assembly).
        /// </summary>
        static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            if (args.Name != null && args.Name.StartsWith("Microsoft.Build", StringComparison.OrdinalIgnoreCase))
            {
                foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    if (string.Equals(assembly.FullName, args.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        return(assembly);
                    }
                }
            }

            return(null);
        }
Exemple #59
0
 private static Assembly CurrentDomain_AssemblyResolve(
     object sender, ResolveEventArgs args)
 {
     return(Assembly.GetExecutingAssembly().FullName == args.Name ?
            Assembly.GetExecutingAssembly() : null);
 }
        private static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
        {
            // since this assembly has deep link to "nunit.framework", use any already loaded "nunit.framework" assembly from test app domain

            if (args.Name.Contains("nunit.framework"))
            {
                return(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == "nunit.framework"));
            }

            return(null);
        }