Mono Cecil error generating PDB

天涯浪子 提交于 2019-12-10 16:48:05

问题


The code below allows me to change methods body and save back the assembly.

        // Recreate PDB
        var assemblyResolver = new DefaultAssemblyResolver();
        var assemblyLocation = Path.GetDirectoryName(pathBin);
        assemblyResolver.AddSearchDirectory(assemblyLocation);
        /*if (!string.IsNullOrEmpty(HintPath))
        {
            assemblyResolver.AddSearchDirectory(HintPath);
        }*/
        var silverlightAssemblyPath = Environment.ExpandEnvironmentVariables(@"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\");
        assemblyResolver.AddSearchDirectory(silverlightAssemblyPath);
        var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver };
        var writerParameters = new WriterParameters();
        var pdbName = Path.ChangeExtension(pathBin, "pdb");
        if (createPDB && File.Exists(pdbName))
        {
            var symbolReaderProvider = new PdbReaderProvider();
            readerParameters.SymbolReaderProvider = symbolReaderProvider;
            readerParameters.ReadSymbols = true;
            writerParameters.WriteSymbols = true;
        }
        //Gets the AssemblyDefinition of "MyLibrary"
        AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(pathBin, readerParameters);
        System.IO.File.Delete(pathBin.Replace(".dll", ".back"));
        assembly.Write(pathBin.Replace(".dll", ".back"));

        if (assembly.Modules.SelectMany(m => m.Types.SelectMany(t => t.Methods.Select(meth => new MethodDefinitionEx(assembly, t, meth))))
            .Where(exp)
            .Any())
        {
            //Save
            if (createPDB)
                assembly.Write(pathBin, writerParameters);
            else
                assembly.Write(pathBin);
            return true;
        }
        return false;

But when I ask cecil to create the symbols file (pdb), the created file is quite different from the original and I can't debug the resulting assembly.

I've found this references on google...but nothing works for me.

  • johnhmarks.wordpress.com/2011/01/19/getting-mono-cecil-to-rewrite-pdb-files-to-enable-debugging
  • groups.google.com/forum/#!topic/mono-cecil/s0Dc3GSgsHY
  • github.com/jbevain/cecil/issues/4

Anybody?

来源:https://stackoverflow.com/questions/19770381/mono-cecil-error-generating-pdb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!