Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

create instance error?

dens_odens_o Member Posts: 5
i'm creating a small client application which loads another winForm application from a URL. when the form is instantiated, i get a "no parameterless constructor defined for this object." what do i need to do to correct this? ffg. is the line that returns the error.
downloadedForm = System.Activator.CreateInstance(formType)

any comment is appreciated and thanks.

Comments

  • tsagldtsagld Member Posts: 621
    : i'm creating a small client application which loads another winForm application from a URL. when the form is instantiated, i get a "no parameterless constructor defined for this object." what do i need to do to correct this? ffg. is the line that returns the error.
    : downloadedForm = System.Activator.CreateInstance(formType)
    :
    : any comment is appreciated and thanks.
    :
    :
    Your CreateInstance call causes the system to instantiate an object of type 'formType'. Therefore, it must call the object's constructor.
    Since you didn't supply any parameters, the system searches for a constructor without arguments.
    Your formtype doesn't have a constructor without arguments, hence the error.
    two solutions:
    - Either add a parameterless constructor to formType
    - Or use
    [code]
    object [] arguments = new Object [number-of-arguments];
    //fill the arguments array with the correct values
    downloadedForm = System.Activator.CreateInstance(formType, arguments);
    [/code]

    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

  • dens_odens_o Member Posts: 5
    thanks, i created a parameterless constructor.

    : Your CreateInstance call causes the system to instantiate an object of type 'formType'. Therefore, it must call the object's constructor.
    : Since you didn't supply any parameters, the system searches for a constructor without arguments.
    : Your formtype doesn't have a constructor without arguments, hence the error.
    : two solutions:
    : - Either add a parameterless constructor to formType
    : - Or use
    : [code]
    : object [] arguments = new Object [number-of-arguments];
    : //fill the arguments array with the correct values
    : downloadedForm = System.Activator.CreateInstance(formType, arguments);
    : [/code]
    :
    : Greets,
    : Eric Goldstein
    : www.gvh-maatwerk.nl
    :
    :

Sign In or Register to comment.