Ejemplo n.º 1
0
        private static byte[] FixDll(AssemblyDefinition asm, string cachePath)
        {
            DefinitionResolver.Fix(asm);

            byte[] bytes;
            using (var stream = new MemoryStream())
            {
                asm.Write(stream);
                bytes = stream.GetBuffer();
            }

            if (cachePath != null)
            {
                try
                {
                    var dir = Path.GetDirectoryName(cachePath);
                    if (dir != null)
                    {
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        File.WriteAllBytes(cachePath, bytes);
                    }
                    else
                    {
                        throw new Exception("Path.GetDirectoryName(cachePath) returned null");
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception($"Exception caching fixed DLL {cachePath}", ex);
                }
            }

            return(bytes);
        }