Mono Cecil Error when applying on .Net Core assemblies

278 views
Skip to first unread message

venu gopal Yela

unread,
Apr 8, 2019, 9:47:42 AM4/8/19
to mono-cecil
Hi JB,

I am using Mono Cecil 0.9.6 version to add MSIL (loggers) on .Net Core. assembly.

Here is the code I am using to read assembly.
AssemblyDefinition.ReadAssembly(targetPhysicalPath, new ReaderParameters { AssemblyResolver = resolver, ReadSymbols = true });


when ReadSymbols is not passed to ReaderParameters(), assembly is loaded fine. Below code is working fine.

AssemblyDefinition.ReadAssembly(targetPhysicalPath, new ReaderParameters { AssemblyResolver = resolver });


Exception stack trace is given below: Can you please help? (Above code is working fine for .Net 4.0)

--------------------------------------

   at Microsoft.Cci.Pdb.MsfDirectory..ctor(PdbReader reader, PdbFileHeader head, BitAccess bits)
   at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Dictionary`2& tokenToSourceMapping, String& sourceServerData, Int32& age, Guid& guid)
   at Mono.Cecil.Pdb.PdbReader.PopulateFunctions()
   at Mono.Cecil.Pdb.PdbReader.ProcessDebugHeader(ImageDebugDirectory directory, Byte[] header)
   at Mono.Cecil.ModuleDefinition.ProcessDebugHeader()
   at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader)
   at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
   at Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters)
   at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters)
   at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
   at Mono.Cecil.AssemblyDefinition.ReadAssembly(String fileName, ReaderParameters parameters)

------------------------------------------

------------------------------------------


Thanks & Regards,

Venu

Jb Evain

unread,
Apr 8, 2019, 3:54:33 PM4/8/19
to mono-...@googlegroups.com
Hello,

You're probably facing a portable pdb, which are not supported in 0.9. I suggest you move to 0.10, please look at http://cecil.pe as it contains information about the breaking changes.

Jb

--
--
--
mono-cecil
---
You received this message because you are subscribed to the Google Groups "mono-cecil" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mono-cecil+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

venu gopal Yela

unread,
Apr 11, 2019, 6:30:36 AM4/11/19
to mono-...@googlegroups.com
Thanks JB. I have choosen pdb only option and version 0.9 worked for me. In case portable pdb is required I will move to version .10.

Regards,
Venu

You received this message because you are subscribed to a topic in the Google Groups "mono-cecil" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mono-cecil/AhfCDjwZcfk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mono-cecil+...@googlegroups.com.

venu gopal Yela

unread,
Dec 13, 2020, 7:07:49 AM12/13/20
to mono-...@googlegroups.com
Hi JB,

I am using Mono Cecil version 0.11.3.0 to read .Net Core 3.1 assembly. Here is the line of code, that is throwing an exception.

var assembly = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters { ReadSymbols = true });

Exception:
System.BadImageFormatException: 'Format of the executable (.exe) or library (.dll) is invalid.'

Can you please help? (Above line of code is working fine for .Net 4.0) 

Regards,
Venu

Reply all
Reply to author
Forward
0 new messages