Error occurred when trying to create a controller of type 'XYZController'. Make sure controller has a parameterless public constructor

0

The following code works fine when executed from Visual Studio, but as I publish it and create a site in IIS to access it, I get the following error:

Code:

public class HelloController : ApiController
    {     

        public string HelloMethod()
        {
            return "Hello World";
        }

    }

Error:

An error has occurred.","ExceptionMessage":"An error occurred when trying to create a controller of
type 'HelloController'. 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.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()","InnerException":{"Message":"An error has
occurred.","ExceptionMessage":"Retrieving the COM class factory for component with CLSID
{A59E7747-3284-435B-8947-4E004361A6AC} failed due to the following error: 80040154 Class not registered (Exception
from HRESULT: 0x80040154
(REGDB_E_CLASSNOTREG)).","ExceptionType":"System.Runtime.InteropServices.COMException","StackTrace":" at
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)\r\n at System.RuntimeType.CreateInstanceSlow(Boolean
publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)\r\n at
System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n at System.Activator.CreateInstance(Type type)\r\n at
GSWebAPI.Controller.GSConfigController..ctor()\r\n at lambda_method(Closure )\r\n at
System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor
controllerDescriptor, Type controllerType)"}}
At line:1 char:1
+ curl http://localhost:8080/api/Hello/HelloMethod
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
c#
asp.net-web-api
asked on Stack Overflow Jan 8, 2019 by Aniruddha • edited Jan 8, 2019 by Aniruddha

1 Answer

0

This is resolved now, only following was required. Thanks everyone for their inputs

Right click on the Application Pool and select Advanced settings - In General section set Enable 32 bit applications to True

answered on Stack Overflow Jan 8, 2019 by Aniruddha

User contributions licensed under CC BY-SA 3.0