private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { var name = new AssemblyName(args.Name).Name.Replace('-', '.'); if (name.StartsWith(m_rootNamespace)) return null; for (int i = 0; i < m_resourceName.Length; ++i) { if (m_resourceName[i].Contains(name)) { byte[] buff; using (var comp = new MemoryStream((byte[])m_resourceMethod[i].GetValue(null, null))) using (var gzip = new GZipStream(comp, CompressionMode.Decompress)) using (var uncomp = new MemoryStream(4096)) { gzip.CopyTo(uncomp); buff = uncomp.ToArray(); } return Assembly.Load(buff); } } return null; }
public Assembly FindAssemblies(object sender, ResolveEventArgs args) { // If a linkable component loads additional assemblies OmiEd might // have issues resolving them // This will help by guessing that the additional assembly might be // in the same folder as the linkable component assembly and trying that. // Not guarantied to work but definitely does help in some cases. var name = new AssemblyName(args.Name).Name; if (name.EndsWith(".resources") || name.StartsWith("System.") || name.EndsWith(".XmlSerializers")) { // don't clutter session log with these return null; } Assembly assembly; string file; FileInfo fi; var sb = new StringBuilder(); bool loaded = false; try { sb.Append(string.Format("AssemblyLoader({0}).FindAssemblies({1})", _caption, name)); if (_loaded.TryGetValue(name, out assembly)) { sb.AppendLine(); sb.AppendLine(string.Format("\tPreviously loaded as({0})", assembly.EscapedCodeBase)); return assembly; } if (args.RequestingAssembly != null) { var uri = Utilities.AssemblyUri(args.RequestingAssembly); AddSearchUri(uri); } var folderpath = string.Empty; foreach (string extension in _potentialAssemblyExtensions) { file = name; if (!file.EndsWith(extension)) file = name + extension; foreach (var uri in _uris) { if (!Utilities.UriIsExistingFolderPath(uri, out folderpath)) continue; fi = new FileInfo(Path.Combine(folderpath, file)); if (!fi.Exists) continue; sb.AppendLine(); sb.Append(string.Format("\tLoadFrom({0})", fi.FullName)); assembly = Assembly.LoadFrom(fi.FullName); if (assembly != null) { loaded = true; _loaded.Add(name, assembly); return assembly; } } } return null; } finally { if (args.RequestingAssembly != null) sb.AppendFormat("\t\tRequestingAssembly\r\n\t\t\t{0}\r\n\t\t\t{1}\r\n", args.RequestingAssembly.FullName, args.RequestingAssembly.CodeBase); if (loaded) Trace.TraceInformation(sb.ToString()); else { sb.Append(", unfound"); Trace.TraceWarning(sb.ToString()); } } }
static void UpdateNuspec([NotNull] string executionDirectoryPath, [NotNull] string assemblyPath, [NotNull] out string nuspecPath) { Console.Write("Updating nuspec..."); var assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath); Debug.Assert(assembly != null); AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += (sender, e) => { Debug.Assert(e != null); Debug.Assert(e.Name != null); var name = new AssemblyName(e.Name).Name; Debug.Assert(name != null); if (name.StartsWith("System.", StringComparison.Ordinal)) { return Assembly.ReflectionOnlyLoad(e.Name); } var assemblyDirectoryPath = Path.GetDirectoryName(assemblyPath); Debug.Assert(assemblyDirectoryPath != null); var packagesPath = Path.Combine(assemblyDirectoryPath, @"..\..\..\packages"); var file = Directory.EnumerateFiles(packagesPath, name + ".dll", SearchOption.AllDirectories).Single(); Debug.Assert(file != null); return Assembly.ReflectionOnlyLoadFrom(file); }; nuspecPath = Path.Combine(executionDirectoryPath, Path.GetFileNameWithoutExtension(assemblyPath) + ".nuspec"); var nuspec = File.ReadAllText(nuspecPath, Encoding.UTF8); ReplacePlaceholders(ref nuspec, assembly); File.WriteAllText(nuspecPath, nuspec, Encoding.UTF8); Console.WriteLine("done"); }
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) { var name = new AssemblyName(args.Name).Name.Replace('-', '.'); if (name.StartsWith("Decchi")) return null; for (int i = 0; i < m_resourceName.Length; ++i) { if (m_resourceName[i].Contains(name)) { byte[] buff = (byte[])m_resourceMethod[i].GetValue(null); if (m_resourceName[i].EndsWith(".dll", StringComparison.CurrentCultureIgnoreCase)) { using (var uncomp = new MemoryStream(204800)) { using (var comp = new MemoryStream(buff)) using (var gzip = new GZipStream(comp, CompressionMode.Decompress)) gzip.CopyTo(uncomp); buff = uncomp.ToArray(); } } return Assembly.Load(buff); } } return null; }
private Assembly HandlerImpl(object sender, ResolveEventArgs args) { if (_ignore) return null; var id = new AssemblyName(args.Name).Name; Assembly result; if (_cached.TryGetValue(id, out result)) return result; if (string.Equals(id, "System.Web", StringComparison.OrdinalIgnoreCase)) { if (MessageBox.Show("Looks like you don’t have .NET 4.5.2 installed. Would you like to install it?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Asterisk) == MessageBoxResult.Yes) { Process.Start("http://www.microsoft.com/en-us/download/details.aspx?id=42642"); } Environment.Exit(10); } #if LOCALIZABLE if (name == "Content Manager.resources" && _first) { Log(">> Content Manager.resources <<"); return null; } if (name.EndsWith(".resources")) { var culture = splitted.ElementAtOrDefault(2)?.Split(new[] { "Culture=" }, StringSplitOptions.None).ElementAtOrDefault(1); Log("culture: " + culture); if (culture == "neutral") return null; var resourceId = CultureInfo.CurrentUICulture.IetfLanguageTag; if (!string.Equals(resourceId, "en-US", StringComparison.OrdinalIgnoreCase)) { name = name.Replace(".resources", "." + resourceId); Log("localized: " + name); } else { Log("skip: " + args.Name); return null; } } #else if (id.StartsWith("PresentationFramework") || id.EndsWith(".resources")) return null; #endif if (id == "Magick.NET-x86") return null; if (_logFilename != null) { Log("Resolve: " + args.Name + " as " + id); } try { _ignore = true; result = Extract(id); if (OptionCache) { _cached[id] = result; } return result; } finally { _ignore = false; } }