6

I am creating a .NET method based on raw IL. I would like to wrap the stand-alone newly created method into a .NET assembly and write this assembly to disk as a foo.dll file in order to then feed this assembly to PEVerify or ILVerify. Indeed, those tools are invaluable when it comes to debugging large bespoke IL sequences.

Does anyone knows how to do this with .NET Core?

Joannes Vermorel
  • 8,976
  • 12
  • 64
  • 104
  • Use [ilasm](https://stackoverflow.com/a/45821503/21567). – Christian.K Feb 04 '19 at 11:13
  • 2
    `PEVerify` is tied to the full framework. Look like `ILVerify` might be the tool you're looking for: "[ILVerify](https://github.com/dotnet/corert/tree/master/src/ILVerify) is a cross-platform, open-source tool currently being developed as part of Microsoft’s CoreRT repository. The goal of ILVerify is to alleviate PEVerify’s limitations..." – spender Feb 04 '19 at 11:16
  • 2
    @Christian.K "ilproj" is also useful - let's you work from the IDE – Marc Gravell Feb 04 '19 at 12:02
  • @spender Thanks a lot for the ILVerify tip! Just updated the question accordingly. – Joannes Vermorel Feb 04 '19 at 19:51
  • You can also use Mono Cecil and some C# code, https://github.com/jbevain/cecil – Lex Li Feb 04 '19 at 23:57
  • @JoannesVermorel What exactly do you need to know, how to create method from IL raw, or how to wrap it in a new assembly, or how to verify it? – Dudi Keleti Feb 11 '19 at 14:10
  • I am seeking a way to move a method - any method - into a isolated assembly on disk (assuming the method is self-contained). – Joannes Vermorel Feb 11 '19 at 14:33
  • What's incredible is that the documentation for AssemblyBuilder in .net5 talks a ton about saving and even has an example calling Save but the method isn't actually there. Microsoft's documentation quality has gone down the toilet in the last 10 years... – Emperor Eto Feb 25 '21 at 00:18

1 Answers1

12

It appears that this problem has been pending for almost 4 years. In the end, we rolled out our own open source alternative to AssemblyBuilder.Save for .NET Core.

Joannes Vermorel
  • 8,976
  • 12
  • 64
  • 104