title: Value cannot be null. Parameter name: type
body: <p>After having read and tried the answers on stackExchange I am still getting a null value for result in the below code:</p>
  <pre><code>    typeOfIMydServiceBase.Assembly
              .GetExportedTypes()
              .Where(exportedType =&gt; typeOfMydServiceBase != exportedType &amp;&amp; typeOfMydServiceBase.IsAssignableFrom(exportedType))
              .Select(mydServiceType =&gt; new
              {
                  serviceType = mydServiceType,
                  interfaceType = mydServiceType.GetInterfaces().First(@interface =&gt; @interface != typeOfIMydServiceBase &amp;&amp; typeOfIMydServiceBase.IsAssignableFrom(@interface))
              })
              .ToList()
              .ForEach(registrationInfo =&gt; container.Register(registrationInfo.interfaceType, () =&gt;
              {
                  var method = serviceActivatorType
                      .GetMethod(&quot;GetService&quot;, serviceActivatorParams)
                      .MakeGenericMethod(new[] { registrationInfo.interfaceType });
                  var result = method.Invoke(new ServiceActivator(), null);
  
                  return result;
              }, WebApiRequestLifestyleWithDisposal));
  </code></pre>
  <p>result keeps coming back as null and when I use an Object[] {null} or Object[]{} or Object[]{null,null,etc} I get parameter mismatches.</p>
  <p>Note: this is the error message I recieve for the above code:</p>
  <blockquote>
  <p>Line 156:                        .MakeGenericMethod(new[] { registrationInfo.interfaceType });</p>
  <p>Line 157:</p>
  <p>Line 158:                    var result = method.Invoke(new ServiceActivator(), null);</p>
  <p>Line 159:</p>
  <p>Line 160:                    return result;</p>
  </blockquote>
  <p>Does anyone know what's happening here and how I can fix it????</p>
  <pre><code>{
  public class ServiceActivator
  {
      public ServiceActivator();
      public ServiceActivator(IServiceConfigurationReader configurationReader);
  
      public T GetService&lt;T&gt;();
      public T GetService&lt;T&gt;(string key);
  }
  </code></pre>
  <p>}</p>
  <p>Also pertinent to the above is the registration of the services used. See below:</p>
  <pre><code>//Scan and register business servics
          var typeOfIMydServiceBase = typeof(IMydServiceBase);
          var typeOfMydServiceBase = typeof(MydServiceBase);
          var serviceActivatorType = typeof(ServiceActivator);
          var serviceActivatorParams = new Type[0];
  </code></pre>
  <p>Update: using typeof(string) at serviceActivator Params works however I am getting an unhandled exception futher down. Here is the new error:</p>
  <pre><code>Line 166:                    p.ServiceContainer = container;
  Line 167:                });
  Line 168:
  Line 169:                container.RegisterWebApiControllers(config);
  Line 170:            }
  </code></pre>
  <p>which pertains to the following code:</p>
  <pre><code>var typeOfIMydServiceBase = typeof(IMydServiceBase);
          var typeOfMydServiceBase = typeof(MydServiceBase);
          var serviceActivatorType = typeof(ServiceActivator);
          var serviceActivatorParams = new Type[] { typeof(string) };
          
          typeOfIMydServiceBase.Assembly
              .GetExportedTypes()
              .Where(exportedType =&gt; typeOfMydServiceBase != exportedType &amp;&amp; typeOfMydServiceBase.IsAssignableFrom(exportedType))
              .Select(mydServiceType =&gt; new
              {
                  serviceType = mydServiceType,
                  interfaceType = mydServiceType.GetInterfaces().First(@interface =&gt; @interface != typeOfIMydServiceBase &amp;&amp; typeOfIMydServiceBase.IsAssignableFrom(@interface))
              })
              .ToList()
              .ForEach(registrationInfo =&gt; container.Register(registrationInfo.interfaceType, () =&gt;
              {
                  
                  var method = serviceActivatorType
                      .GetMethod(&quot;GetService&quot;, serviceActivatorParams)
                      .MakeGenericMethod(new[] { registrationInfo.interfaceType });
             
                  var result = method.Invoke(new ServiceActivator(), null);
  
                  return result;
              }, WebApiRequestLifestyleWithDisposal));
          {
  
              container.RegisterInitializer&lt;IMydServiceBase&gt;(p =&gt;
              {
                  p.ServiceContainer = container;
              });
  
              container.RegisterWebApiControllers(config);
          }
      }
  </code></pre>