title: BoDi.ObjectContainerException thrown when tried to break down my step definitions to multiple file (C#, NUnit, SpecFlow)
body: <p>Initially I used a single step definition for my SpecFlow-C# automation tests, but when it became too long (~2K lines), I tried to break down to smaller pieces.</p>
  
  <p>I used a base to handle my hooks (BeforeTestRun, BeforeScenario, AfterScenario, AfterTestRun), initialize the driver and the logging.
  In the BeforeTestRun, I parse a config file to check which browser do I want to run my tests on, and in the BeforeScenario I init the driver based on that. So something like this:</p>
  
  <pre><code>[Binding]
  public class TestBase
  {
  
      protected TestBase()
      {}
  
      protected      IWebDriver    mDriver;
      private static log4net.ILog  mLogger;
      private static string        mCurrentBrowser;
  
      [BeforeTestRun]
      protected static void BeforeTestRun()
      {
          //Set up the logging and parse config file, give mCurrentBrowser a value
      }
  
  
      [BeforeScenario]
      protected void InitTest()
      {
          if ( mCurrentBrowser == "chrome" )
          {
              mDriver = new ChromeDriver();
          }
      }
  
      //And so on
  
  }
  </code></pre>
  
  <p>I also have a CoreObjects class that contains helper methods used by all/most of my step definition files. It's inheriting from TestBase. The interesting part of that is this:</p>
  
  <pre><code>public class CoreObjects : TestBase
  {
  
      protected CoreObjects( IWebDriver aDriver )
      {
          mDriver = aDriver;
      }
  
      // The rest of the class is helper methods
      // and private member variables used by a couple of helper methods
      // or protected member variables used by the step definitions
  
  }
  </code></pre>
  
  <p>And there are 8-10 step definition files. These are look like the following sample:</p>
  
  <pre><code>[Binding]
  public class SampleStepDefClass : CoreObjects
  {
  
      protected SampleStepDefClass ( IWebDriver aDriver )
          : base( aDriver )
      {  }
  
      [When( @"I do something" )]
      private void DoSomething( string aUrl )
      {
          mDriver.Url = aUrl;
          Thread.Sleep( 800 );
          string lCurrentUrl = mDriver.Url;
          Assert.IsTrue( lCurrentUrl.Contains( aUrl ) );
      }
  }
  </code></pre>
  
  <p>Also have a static class that fires up another static driver and do some preconditional actions, but it shouldn't be an issue, that's a completely detached process.
  When I try to Run SpecFlow Scenarios via Visual Studio 2015, the preconditional static other-driver in the preconditional class does its methods well (it's called in the BeforeTestRun hook). But when the concrete test should run it's only opening and closing the browser (my mDriver).</p>
  
  <p>When I run as Debug SpecFlow Scenarios, the preconditional things worked well, but then (I ran it step by step using F11 to step into lines of codes) the debugger jumped to my second scenario's first step and threw an Exception:</p>
  
  <pre><code>An exception of type 'BoDi.ObjectContainerException' occurred
  in TechTalk.SpecFlow.dll but was not handled in user code
  
  Additional information: Interface cannot be resolved:
  OpenQA.Selenium.IWebDriver (resolution path: MyNamespace.MyFirstStepDefClass)
  </code></pre>
  
  <p>When I use the same exact methods and variables, but only use Binding on TestBase, and (only one) StepDefinition file all my tests work great.
  I have a feeling that either the inheritance or the constructors messing it up, but I'm quite new to C# and SpecFlow, so stuck :-/
  Couldn't really find anything except that I might need to create an instance of ObjectContainer, and call RegisterInstanceAs function on it with the driver passed as parameter. But either I do it wrong, or that's not the solution.</p>
  
  <p>Thanks!</p>