mono.cecil WriteSymbols 以获取错误的 pdb

mono.cecil WriteSymbols to getnerate pdb with error

    MonoCecilInjectionLogs Error:Object reference not set to an instance of an object. StackTrace:  at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR (System.Int32 errorCode) [0x0000a] in <fb001e01371b4adca20013e0ac763896>:0 
  at (wrapper cominterop) Mono.Cecil.Pdb.ISymUnmanagedWriter2.CloseMethod()
  at (wrapper cominterop-invoke) Mono.Cecil.Pdb.ISymUnmanagedWriter2.CloseMethod()
  at Mono.Cecil.Pdb.SymWriter.CloseMethod () [0x00000] in <eaeb8e4134e34483990c08dba7529711>:0 
  at Mono.Cecil.Pdb.NativePdbWriter.Write (Mono.Cecil.Cil.MethodDebugInformation info) [0x00081] in <eaeb8e4134e34483990c08dba7529711>:0 
  at Mono.Cecil.Cil.CodeWriter.WriteUnresolvedMethodBody (Mono.Cecil.MethodDefinition method) [0x00086] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.Cil.CodeWriter.WriteMethodBody (Mono.Cecil.MethodDefinition method) [0x00012] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00013] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.MetadataBuilder.AddMethods (Mono.Cecil.TypeDefinition type) [0x00013] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x000a2] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.MetadataBuilder.AddTypes () [0x00018] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00014] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.MetadataBuilder.BuildModule () [0x0009f] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.ModuleWriter+<>c.<BuildMetadata>b__2_0 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.ModuleDefinition.Read[TItem,TRet] (TItem item, System.Func`3[T1,T2,TResult] read) [0x00025] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x0000f] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.ModuleWriter.Write (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x000fb] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.ModuleWriter.WriteModule (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x00002] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00019] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.ModuleDefinition.Write (Mono.Cecil.WriterParameters parameters) [0x0000e] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 
  at Mono.Cecil.AssemblyDefinition.Write (Mono.Cecil.WriterParameters parameters) [0x00000] in <58b86858c52b4b5fbb6efedd16c9c16a>:0 

dll 是 .net 框架工作。我想用 mono.ceil.

注入方法
AssemblyDefinition.Write(new WriterParameters()
{
   WriteSymbols = true,
   SymbolWriterProvider = new Mono.Cecil.Pdb.PdbWriterProvider(),
}) ;

当 WriteSymbols 为 false 时,我可以成功修改 dll。

在 Visual Studio 中将 pdb“pdbonly”设置为“可移植”。