Index: Core/Plugins/src/Core.Plugins.OxyPlot/OxyPlotGuiPlugin.cs =================================================================== diff -u -rb34c0fe58a6c3228733f322c6ba0b86444397368 -rb6dea7374102ce7e7a8f13cf127ea01c36e03eb9 --- Core/Plugins/src/Core.Plugins.OxyPlot/OxyPlotGuiPlugin.cs (.../OxyPlotGuiPlugin.cs) (revision b34c0fe58a6c3228733f322c6ba0b86444397368) +++ Core/Plugins/src/Core.Plugins.OxyPlot/OxyPlotGuiPlugin.cs (.../OxyPlotGuiPlugin.cs) (revision b6dea7374102ce7e7a8f13cf127ea01c36e03eb9) @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Core.Common.Controls.Views; using Core.Common.Gui; @@ -16,6 +17,7 @@ { private ChartingRibbon chartingRibbon; private LegendController legendController; + private bool activated; public override IRibbonCommandHandler RibbonCommandHandler { @@ -32,6 +34,7 @@ legendController.ToggleLegend(); Gui.ActiveViewChanged += GuiOnActiveViewChanged; + activated = true; } public override IEnumerable GetViewInfoObjects() @@ -61,7 +64,10 @@ public override void Dispose() { - Gui.ActiveViewChanged -= GuiOnActiveViewChanged; + if (activated) + { + Gui.ActiveViewChanged -= GuiOnActiveViewChanged; + } base.Dispose(); } Index: Core/Plugins/test/Core.Plugins.OxyPlot.Test/OxyPlotGuiPluginTest.cs =================================================================== diff -u -rb34c0fe58a6c3228733f322c6ba0b86444397368 -rb6dea7374102ce7e7a8f13cf127ea01c36e03eb9 --- Core/Plugins/test/Core.Plugins.OxyPlot.Test/OxyPlotGuiPluginTest.cs (.../OxyPlotGuiPluginTest.cs) (revision b34c0fe58a6c3228733f322c6ba0b86444397368) +++ Core/Plugins/test/Core.Plugins.OxyPlot.Test/OxyPlotGuiPluginTest.cs (.../OxyPlotGuiPluginTest.cs) (revision b6dea7374102ce7e7a8f13cf127ea01c36e03eb9) @@ -50,15 +50,17 @@ public void Activate_WithGui_InitializesComponentsAndBindsActiveViewChanged() { // Setup + var mocks = new MockRepository(); + using (var plugin = new OxyPlotGuiPlugin()) { - var mocks = new MockRepository(); var gui = mocks.StrictMock(); var dockingManger = mocks.Stub(); var toolWindows = new ViewList(dockingManger, null); var view = mocks.StrictMock(); gui.Expect(g => g.ActiveViewChanged += null).IgnoreArguments(); + gui.Expect(g => g.ActiveViewChanged -= null).IgnoreArguments(); gui.Expect(g => g.ToolWindowViews).Return(toolWindows).Repeat.Twice(); gui.Expect(g => g.OpenToolView(Arg.Matches(c => true))); gui.Expect(g => g.ActiveView).Return(view); @@ -73,8 +75,8 @@ // Assert Assert.IsInstanceOf(plugin); Assert.NotNull(plugin.RibbonCommandHandler); - mocks.VerifyAll(); } + mocks.VerifyAll(); } [Test]