public void UpdateILSpyObjectModel(object sender, EventArgs empty) { var plugin = PluginFactory.GetInstance() as ILSpyPlugin; if (plugin == null) { return; } var context = plugin.GetAssemblyContext(ActiveItem as ILSpyTreeNode); if (context == null) { return; } var adef = context.AssemblyDefinition; var wrapper = HostAssemblies.FirstOrDefault(a => a.Location == adef.MainModule.Image.FileName) as ILSpyAssemblyWrapper; if (wrapper == null) { return; } var loadedAssembly = wrapper.LoadedAssembly; try { // Ok we have everything, write the assembly to stream var stream = new MemoryStream(); adef.MainModule.Write(stream); stream.Position = 0; // Then hot-replace the assembly _hotReplacingAssembly = true; loadedAssembly.AssemblyList.HotReplaceAssembly(loadedAssembly.FileName, stream); } catch (Exception) { ShowMessage("Unable to stream assembly to ILSpy. In case of item deletion make sure you removed all existing references."); } finally { _hotReplacingAssembly = false; } }
public void UpdateHostObjectModel(object sender, EventArgs empty) { var plugin = PluginFactory.GetInstance(); if (plugin == null) { return; } var context = plugin.GetAssemblyContext(ActiveItem); if (context == null) { return; } var adef = context.AssemblyDefinition; var wrapper = HostAssemblies.FirstOrDefault(a => a.Location == adef.MainModule.Image.FileName); if (wrapper == null) { return; } try { // Ok we have everything, write the assembly to stream var stream = new MemoryStream(); adef.MainModule.Write(stream); stream.Position = 0; // Then hot-replace the assembly UpdatingHostObjectModel = true; HotReplaceAssembly(wrapper, stream); } catch (Exception) { ShowMessage(string.Format("Unable to stream assembly to {0}. In case of item deletion make sure you removed all existing references.", plugin.HostApplication)); } finally { UpdatingHostObjectModel = false; } }