Which Activator.CreateInstance overload function to call? I have a type returned from
“Type proxyType = GetProxyType(contractType);” and the constructorinfo is
“[System.Reflection.RuntimeConstructorInfo] = {Void .ctor(System.ServiceModel.InstanceContext)}
base {System.Reflection.MemberInfo} = {Void .ctor(System.ServiceModel.InstanceContext)}
[System.Reflection.RuntimeConstructorInfo] = {Void .ctor(System.ServiceModel.InstanceContext, System.String)}
base {System.Reflection.MethodBase} = {Void .ctor(System.ServiceModel.InstanceContext, System.String)}
[System.Reflection.RuntimeConstructorInfo] = {Void .ctor(System.ServiceModel.InstanceContext, System.String, System.String)}
base {System.Reflection.MethodBase} = {Void .ctor(System.ServiceModel.InstanceContext, System.String, System.String)}
[System.Reflection.RuntimeConstructorInfo] = {Void .ctor(System.ServiceModel.InstanceContext, System.String, System.ServiceModel.EndpointAddress)}
base {System.Reflection.MethodBase} = {Void .ctor(System.ServiceModel.InstanceContext, System.String, System.ServiceModel.EndpointAddress)}
[System.Reflection.RuntimeConstructorInfo] = {Void .ctor(System.ServiceModel.InstanceContext, System.ServiceModel.Channels.Binding, System.ServiceModel.EndpointAddress)}
base {System.Reflection.MethodBase} = {Void .ctor(System.ServiceModel.InstanceContext, System.ServiceModel.Channels.Binding, System.ServiceModel.EndpointAddress)}.
Thanks!!
It seems the type has a default constructor so
Activator.CreateInstance(proxyType);should work. If you want to call some other constructor for example the one that take a string parameter you could do this:or the one with two string parameters:
UPDATE:
My mistake there’s no parameterless constructor for this type defined. All constructors need at least one argument which is of type InstanceContext. So in order to create an instance of this type you will need to pass at least the instance context. For example if you are in a WCF you could try this: