A: 

Is the constructor public?

Is the single parameter of type BookingContext?

The trouble is, this is clearly part of a bigger system - it would be much easier to help you if you could produce a short but complete program which demonstrated the problem. Then we could fix the problem in that program, and you could port your fix back to your real system. Otherwisewise we're really just guessing :(

Jon Skeet
point taken, I'll update the post.
Ed Woodcock
+5  A: 

Try this one:

  Type contextType = Type.GetType("CheckoutProcesses." + data.Case.ToString());
  CheckoutContext output = 
      (CheckoutContext)Activator.CreateInstance(contextType, data);

The reason you code doesn't work is that Activator.CreateInstance doesn't really have the overload you want. So you might wonder why the code compiles at all! The reason is, it has an overload that takes (Type type, params object[] args) which matches your method call so it compiles but at runtime, it searches your type for a constructor taking a BindingFlags and a BookingContext[] which is clearly not what your type has.

Mehrdad Afshari
spot on, I obviously shouldn't read the doc pages for classes, they lie! (The doc for Activator.CreateInstance tells you to use (type, object[] params) to call the constructor with the relevant number of arguments inside params!) =D
Ed Woodcock
It doesn't lie. Did it tell you to specify the BindingFlags unless you really need it? ;)
Mehrdad Afshari
Nope, but it didn't work without either! (I've been hacking away at this for a good while now) =D
Ed Woodcock
By the way, you can always right click on the method name in code and use `Go to definition` to see which overload is resolved.
Mehrdad Afshari
Activator.CreateInstance must have one of the most confusing set of overloads in the entire .NET Framework!
Patrick McDonald
It would definitely make me think twice before using a paramarray in any overloaded methods.
Patrick McDonald
A: 

Does the SingleItemNew constructor take BookingContext as parameter? If it does not match exatcly it will fail:

class ParamType   {    }
class DerivedParamType : ParamType    {    }
class TypeToCreate
{
    public TypeToCreate(DerivedParamType data)
    {
        // do something
    }
}

ParamType args = new ParamType();
// this call will fail: "constructor not found"
object obj = Activator.CreateInstance(typeof(TypeToCreate), new object[] { args });

// this call would work, since the input type matches the constructor
DerivedParamType args = new DerivedParamType();
object obj = Activator.CreateInstance(typeof(TypeToCreate), new object[] { args });
Fredrik Mörk
A: 

This worked for me.

Type.GetType("namespace.class, namespace");