Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
//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);
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