Created
May 3, 2016 18:19
-
-
Save JoshVarty/0b7c0c0ffe6aa51140d6fe62384d8250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//See part two for how to generate these two | |
byte[] metadataBytes = ...; | |
byte[] ilBytes = ...; | |
//Find module by name | |
var appDomain = corProcess.AppDomains.Cast<CorAppDomain>().Single(); | |
var assembly = appDomain.Assemblies.Cast<CorAssembly>().Where(n => n.Name.Contains("MyProgram")).Single(); | |
var module = assembly.Modules.Cast<CorModule>().Single(); | |
//I found a bug in the ICorDebug API. Apparently the API assumes that you couldn't possibly have a change to apply | |
//unless you had first fetched the metadata for this module. Perhaps reasonable in the overall scenario, but | |
//its certainly not OK to simply throw an AV exception if it hadn't happened yet. | |
// | |
//In any case, fetching the metadata is a thankfully simple workaround | |
object import = module.GetMetaDataInterface(typeof(IMetadataImport).GUID); | |
corProcess.Stop(-1); | |
module.ApplyChanges(metadataBytes, ilBytes); | |
corProcess.Continue(outOfBand: false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment