title: I'm not using dependency injection, but I'm getting "An error occurred when trying to create a controller of type"
body: <p>I've seen lots of answers about how improper use of dependency injection can cause the error...</p>
  
  <blockquote>
    <p>An error occurred when trying to create a controller of type 'FranchiseUserController'. Make sure that the controller has a parameterless public constructor.</p>
  </blockquote>
  
  <p>but I am not using any dependency injection products like Ninject, Unity, etc.
   Also, this error does not happen in my local development environment, but is showing up when we are testing on our QA server. Furthermore, it occurs intermittently and it occurs with several of my Web API methods. It occurs with multiple users and with multiple browsers.</p>
  
  <p>I'm not sure what code to even post here. Let me know if you need more information and I will be glad to post it.</p>
  
  <p>This is an ASP.NET MVC / WebAPI application using AngularJS. The error occurs when calling the Web API controller from an Angular client. The angular app is receiving a response in the Error callback with a 500 Internal Server Error with...</p>
  
  <blockquote>
    <p>Data Exception Message: An error occurred when trying to create a controller of type 'FranchiseUserController'. Make sure that the controller has a parameterless public constructor.
        Data Exception Type: System.InvalidOperationException</p>
  </blockquote>
  
  <p>Here is the constructor from the controller that is mentioned in the error and the method that was being called.</p>
  
  <p>The constructor</p>
  
  <pre><code>public FranchiseUserController()
  {
      _sm = new SettingManager();
      _millicare_connectionString = _sm.conn_MilliCareSvcConnectionString();
      _maa_connectionString = _sm.conn_MaaSvcConnectionString();
  
      if (AppConstants.OverrideSecurityLocal &amp;&amp; _sm.ServiceConfiguration() == ServiceConfigurationValues.LOCAL)
      {
          _acsUser.Name = Environment.UserName;
          _acsUser.MaaUserGuid = _sm.developerAdGuid().ConvertAdGuidToMaaGuid();
          _acsUser.Role = _sm.app_TestUserRole();
      }
      else {
          ClaimsPrincipal userClaims = (ClaimsPrincipal)this.User;
          _acsUser.Name = ((ClaimsIdentity)userClaims.Identity).FindFirst(MiddlewareClaimTypes.Name).Value;
          _acsUser.MaaUserGuid = ((ClaimsIdentity)userClaims.Identity).FindFirst(MiddlewareClaimTypes.MaaUserGuid).Value;
          _acsUser.Role = AppConstants.RoleNotAuthorized;
  
          //Get user role
          if (ApplicationMiddleware.Security.Extensions.HasClaim(userClaims, AppConstants.Maint_Option, AppConstants.Maint_Action, AppConstants.Maint_SecureValue_Approver, _sm.acs_MAAFranchiseResourceMaint()))
          {
              _acsUser.Role = AppConstants.RoleApprover;
          }
          else if (ApplicationMiddleware.Security.Extensions.HasClaim(userClaims, AppConstants.Maint_Option, AppConstants.Maint_Action, AppConstants.Maint_SecureValue_Admin, _sm.acs_MAAFranchiseResourceMaint()))
          {
              _acsUser.Role = AppConstants.RoleAdmin;
          }
          else if (ApplicationMiddleware.Security.Extensions.HasClaim(userClaims, AppConstants.Resource_Option, AppConstants.Resource_Action, AppConstants.Resource_SecureValue_Franchise, _sm.acs_MAAFranchiseResourceReports()))
          {
              _acsUser.Role = AppConstants.RoleFranchise;
          }
      }
  }
  </code></pre>
  
  <p>...and the method</p>
  
  <pre><code>[ValidateCustomAntiForgeryToken]
  [HttpPost]
  public HttpResponseMessage UpdateAddress(Address_dto Value)
  {
      HttpResponseMessage srvresponse = new HttpResponseMessage();
  
      if (_acsUser.Role == AppConstants.RoleAdmin || _acsUser.Role == AppConstants.RoleApprover)
      {
          Value.modified_user = _acsUser.Name;
          srvresponse = WrapServiceCall&lt;string&gt;((serviceResult, responseMessage) =&gt;
          {
              MilliCareSvcClient().Using(svc =&gt;
              {
                  serviceResult.OperationSuccessful = svc.UpdateAddress(Value);
              });
          });
          return srvresponse;
      }
      else
      {
          var noaccessServiceResult = new ServiceResult&lt;string&gt;();
          noaccessServiceResult.SetUnauthorizedMessage();
          srvresponse.Content = new ObjectContent&lt;ServiceResult&lt;string&gt;&gt;(noaccessServiceResult, new System.Net.Http.Formatting.JsonMediaTypeFormatter());
          return srvresponse;
      }
      //});
  }
  </code></pre>