public static Assembly Load(string assemblyName) { string path = Path.Combine(MSNUtility.GetMSNCorePath(), assemblyName); AssemblyName name = AssemblyName.GetAssemblyName(path); Assembly assembly = Assembly.Load(name); return(assembly); }
private static Assembly Domain_AssemblyResolve(object sender, ResolveEventArgs args) { try { //Retrieve the list of referenced assemblies in an array of AssemblyName. Assembly objExecutingAssemblies = Assembly.GetExecutingAssembly(); AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies(); string dirAssemblies = MSNUtility.GetMSNCorePath(); if (Directory.Exists(dirAssemblies)) { string dirSeparator = Path.DirectorySeparatorChar.ToString(); if (!dirAssemblies.EndsWith(dirSeparator)) { dirAssemblies += dirSeparator; } string assemblyName = string.Empty; string fileName = string.Empty; int p = args.Name.IndexOf(","); assemblyName = (p > 0) ? args.Name.Substring(0, p) : assemblyName.Replace(".dll", string.Empty); fileName = assemblyName + ".dll"; string[] files = Directory.GetFiles(dirAssemblies, fileName, SearchOption.AllDirectories); /// Do not use the following function as CLR produceds StackOverflowException /// http://blogs.msdn.com/b/junfeng/archive/2004/09/29/235763.aspx /// DirectoryUtility.GetFiles(dirAssemblies, fileName, SearchOption.AllDirectories); if (files != null && files.Length > 0) { Assembly assembly = LoadFrom(files[0]); if (m_preJitMethods) { PreJITMethodsThread(assembly); } return(assembly); } string path = string.Empty; string[] dirList = GetDirectories(dirAssemblies).ToArray(); //Loop through the array of referenced assembly names. foreach (AssemblyName asmName in arrReferencedAssmbNames) { //Check for the assembly names that have raised the "AssemblyResolve" event. if (asmName.FullName.Substring(0, asmName.FullName.IndexOf(",")) == assemblyName) { if (dirList.Length > 0) { foreach (string strDirPath in dirList) { //Build the path of the assembly from where it has to be loaded. //The following line is probably the only line of code in this method you may need to modify: path = Path.Combine(strDirPath, fileName); if (File.Exists(path)) { //Load the assembly from the specified path. Assembly assembly = LoadFrom(path); if (m_preJitMethods) { PreJITMethodsThread(assembly); } return(assembly); } } } else { path = Path.Combine(dirAssemblies, fileName); if (File.Exists(path)) { //Load the assembly from the specified path. Assembly assembly = LoadFrom(path); if (m_preJitMethods) { PreJITMethodsThread(assembly); } return(assembly); } } } } } } catch { } return(null); }