title: An error occurred when trying to create a controller, Make sure that the controller has a parameterless public constructor
body: <p>I am getting the below error on an inconsistent basis when calling a specific method on my controller:</p>
  
  <blockquote>
    <p>An error occurred when trying to create a controller of type 'TimelineController'. Make sure that the controller has a parameterless public constructor.</p>
  </blockquote>
  
  <p>The confusing part is that this method does occasionally work, and that the controller itself does have a parameterless constructor. Here's a brief example of the code:</p>
  
  <pre><code>[Authorize]
  [RoutePrefix("api/timeline")]
  public class TimelineController : CherishApiController
  {
      private readonly TimelineEventRepository _timelineEventRepository;
      private readonly BlobHelper _blobHelper;
      private readonly ChildHelper _childHelper;
      private readonly AccountHelper _accountHelper;
  
      public TimelineController()
      {
          _timelineEventRepository = new TimelineEventRepository();
          _blobHelper = new BlobHelper();
          _childHelper = new ChildHelper();
          _accountHelper = new AccountHelper();
      }
  
      [HttpPost]
      [Route("UploadImage")]
      [ResponseType(typeof(UploadMediaResponse))]
      public async Task&lt;HttpResponseMessage&gt; UploadImage()
      {
          try
          {
              return await Upload(Request.Content, MediaType.Image);
          }
          catch (Exception ex)
          {
              return ErrorResponse(ex);
          }
      }
  
      private async Task&lt;HttpResponseMessage&gt; Upload(HttpContent requestContent, string mediaType)
      {
          // reads the data from the multi-part request and stores a record in an Azure DocumentDB
      }
  }
  </code></pre>
  
  <p>As you can see I'm not using any form of dependency injection (as this is a small non-essential web-app) and pretty much all of the solutions I've seen when researching are involving a DI setup issue.</p>
  
  <p>Here is the full stack trace if it helps:</p>
  
  <pre><code>An error occurred when trying to create a controller of type 'TimelineController'. Make sure that the controller has a parameterless public constructor.","ExceptionType":"System.InvalidOperationException","StackTrace":"  
     at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n  
     at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)\r\n
     at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__1.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"One or more errors occurred.","ExceptionType":"System.AggregateException","StackTrace":"
     at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n
     at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)\r\n
     at System.Threading.Tasks.Task`1.get_Result()\r\n
     at Microsoft.Azure.Documents.Linq.DocumentQuery`1.GetEnumerator()\r\n
     at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\r\n
     at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\r\n
     at Cherish.Domain.Repositories.Implementation.DocumentRepository`1.ReadOrCreateDatabase()\r\n
     at Cherish.Domain.Repositories.Implementation.DocumentRepository`1..ctor()\r\n
     at lambda_method(Closure )\r\n
     at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"An error occurred while sending the request.","ExceptionType":"System.Net.Http.HttpRequestException","StackTrace":"
     at Microsoft.Azure.Documents.BackoffRetryUtility`1.&lt;ExecuteAsync&gt;d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
     at Microsoft.Azure.Documents.Linq.DocumentQueryExecutionContext.&lt;ExecuteAllAsync&gt;d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
     at Microsoft.Azure.Documents.Linq.DocumentQuery`1.&lt;GetEnumeratorTAsync&gt;d__10.MoveNext()","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Unable to connect to the remote server","ExceptionType":"System.Net.WebException","StackTrace":"
     at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)\r\n
     at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)","InnerException":{"Message":"An error has occurred.","ExceptionMessage":"An attempt was made to access a socket in a way forbidden by its access permissions","ExceptionType":"System.Net.Sockets.SocketException","StackTrace":"
     at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n
     at System.Net.Sockets.Socket.InternalBind(EndPoint localEP)\r\n
     at System.Net.Sockets.Socket.BeginConnectEx(EndPoint remoteEP, Boolean flowContext, AsyncCallback callback, Object state)\r\n
     at System.Net.Sockets.Socket.UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, Object state)\r\n
     at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket&amp; socket, IPAddress&amp; address, ConnectSocketState state, IAsyncResult asyncResult, Exception&amp; exception)"}}}}}
  </code></pre>
  
  <p>Can anyone guide me on what the issue is? </p>