Question

I get this error when trying to run my web service, WizardService.asmx:

System.MissingMethodException: No parameterless constructor defined for this object.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Web.Services.Protocols.ServerProtocol.CreateServerInstance()
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

Here is my web service code in C#

[WebService(Namespace = "http://www.tempuri.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WizardService : WebService
{
    private EventLog eventLog;

    private WizardService()
    {
        eventLog = new EventLog("EktronWizardServiceLog", "localhost", "EktronWizardService");
    }

Everywhere I have looked online (including this site) seems to indicate this error message has something to do with MVC, but I am not using MVC. This is an ASMX .Net 4.5 web service.

Was it helpful?

Solution

You have private parameter less constructor which is not accessible outside the class. Make the construct public so that it could be accessed outside the class for constructing objects of WizardService.

public WizardService()
{
    eventLog = new EventLog("EktronWizardServiceLog", "localhost", "EktronWizardService");
}

Access Modifiers (C# Programming Guide)

public The type or member can be accessed by any other code in the same assembly or another assembly that references it.

private The type or member can be accessed only by code in the same class or struct.

protected The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.

internal The type or member can be accessed by any code in the same assembly, but not from another assembly.

You can read more about access modifiers here.

OTHER TIPS

Problem : You have declared your Constructor with private access modifier. so it is not accessible outside the class to construct the objects.

Solution : You should have public access modifier for the constructors tobe accessed from outside the class to construct the Objects.

Replace This:

private WizardService()

With This:

public WizardService()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top