Пример #1
0
        public static Assembly AssemblyLoad(string asssemblyName)
        {
            var shortName = new AssemblyName(asssemblyName).Name;

            shortName = shortName.Replace(".resources", "");
            if (!_loaded.ContainsKey(shortName))
            {
                Func <string, string> resourceFormat =
                    ext =>
                    String.Format("KeyczarTool.Minified.Diminish.refs.{0}.{1}.dep-lzma", shortName, ext);

                var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceFormat("dll"))
                             ?? Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceFormat("exe"));
                if (stream == null)
                {
                    throw new Exception(string.Format(
                                            "Missing embedded dependency {0} was looking for resource {1} or {2}", asssemblyName,
                                            resourceFormat("dll"), resourceFormat("exe")));
                }
                using (stream)
                {
                    var    pdb     = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceFormat("pdb"));
                    byte[] symbols = null;

                    if (pdb != null)
                    {
                        using (pdb)
                            using (var memStream = new MemoryStream())
                            {
                                Zipper.Decode(pdb, memStream);
                                symbols = memStream.ToArray();
                            }
                    }

                    using (var memStream = new MemoryStream())
                    {
                        Zipper.Decode(stream, memStream);
                        var assembly = symbols == null
                                           ? Assembly.Load(memStream.ToArray())
                                           : Assembly.Load(memStream.ToArray(), symbols);

                        _loaded.Add(shortName, assembly);
                    }
                }
            }
            return(_loaded[shortName]);
        }