I get the following error:
Test method: BootStrapperTest.Can_Create_Alert_Management_Object threw exception: Ninject.ActivationException: Error activating IAlertManagement No matching bindings are available, and the type is not self-bindable. Activation path: 1) Request for IAlertManagement Suggestions: 1) Ensure that you have defined a binding for IAlertManagement. 2) If the binding was defined in a module, ensure that the module has been loaded into the kernel. 3) Ensure you have not accidentally created more than one kernel. 4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name. 5) If you are using automatic module loading, ensure the search path and filters are correct.
Here is an example that throws this exception:
[TestInitialize] public void Initialize() { BootStrapper.RegisterTypes(); } [TestMethod] public void Can_Create_Alert_Management_Object() { IAlertManagement alertManagementService = BootStrapper.Kernel.Get<IAlertManagement>(); Assert.IsNotNull(alertManagementService); } //This is the code that gets called in [TestInitialize] public static void RegisterTypes() { if (!initialized) { Kernel.Bind(scanner => scanner.FromAssembliesMatching("MyCompany.MyProduct.*") .SelectAllClasses() .BindDefaultInterface()); Kernel.Unbind(typeof(IWcfServiceClient<>)); Kernel.Bind(typeof(IWcfServiceClient<>)).ToMethod(ctx => (ctx.Kernel.Get(typeof(WcfServiceClientProvider<>).MakeGenericType(ctx.GenericArguments)) as IProvider).Create(ctx)); } initialized = true; }
The indicated error occurs in one of my unit tests on our build server, but not on my development machine. I have 7 other tests, almost identical to this, that pass on the build server and on my development machine, but this is the only test that fails.
The IAlertManagement interface comes from a dll named Core , and the specific type comes from another dll called AlertManagement . I have both a Core dll and AlertManagement included in my unit test project as project references. I have 7 or 8 other tests identical to this situation, but this is the only mistake.
Any ideas would be appreciated.
c # ninject tfsbuild ninject-extensions
Cole w
source share