I am using System.AddIn to load and unload extra add-ins into my WCF application. The application gets it's load/unload command from another app, then it calls the following code.
Dim controller As AddInController = AddInController.GetAddInController(targetAddin)
controller.Shutdown()
In a plain WPF test harness, this code works as expected. In the 'real' app, it throws an exception on the GetAddInController
method that says the add-in was not activated by a token (it was) or has already been shut down (it hasn't). If I run over the line of execution again, it works as expected.
In every other way, this works as expected (the add-in throws an exception after it's been shutdown, the add-in shuts down correctly the second time I try it, etc). I could catch and ignore the first exception, then try again, but this doesn't seem to be the best way to solve the problem.
Why is this exception being thrown on the first call, but working correctly thereafter?