2

Possible Duplicate:
Is there an API for verifying the MSIL of a dynamic assembly at runtime?

I'm dynamically generating an assembly using Reflection.Emit and the like.

For a unit test, I'd like to PEVerify my IL.

I can do it from the command line, but I'd rather do this in code.

Is there a way to do this which is more convenient than calling PEVerify.exe? Ideally, I'd like to directly hand it the dynamic assembly without having to save that assembly to disk first.

Ideally I'm looking for something along the lines of (psuedocode:

Assert.IsFalse(new PEVerifier(myAssembly).Verify().Errors.Any());
Community
  • 1
  • 1
Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
  • 1
    Hm, doing some digging. Looks like the real work is being done by the `VerifyMethod` export in peverify.dll in the framework directory. My general feeling is that you will have to do this in another AppDomain. The PE verify loads the assembly, and all of its dependencies. The command line might just be a better option. – vcsjones Dec 08 '11 at 16:27
  • @MauricioScheffer Agree it's probably a duplicate. I searched for questions tagged `[peverify]` and missed it since it wasn't tagged. – Craig Stuntz Dec 08 '11 at 17:12

1 Answers1

1

You could, as the 'duplicate' question's answer suggests, figure out how to hook into the native DLL used by PEVerify.exe (which I'm guessing would cause issues since it is not documented and probably is subject to change).

The other option would be to use the AssemblyBuilder class to write the dynamic assembly that you're creating to the disk at a temporary location and then call PEVerify.exe via the System.Diagnostics.Process class (much like this PEVerifier class example does).

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
  • That class is helpful, because it's exactly what I was going to write (well, I was going to use F#, but...) if I had to use an assembly on disk, so thanks for that! – Craig Stuntz Dec 08 '11 at 17:47