Anyone know why this won’t compile? The problem has to do with inheriting from the Workflow Activity.
public class MyActivityBase<T> : System.Workflow.ComponentModel.Activity
{
public T MyProperty { get; set; }
}
Compile Error Message
Error 1 Could not create activity of type '...Activities.Common.MyActivityBase`1'. System.ArgumentException: Cannot create an instance of ...Activities.Common.MyActivityBase`1[T] because Type.**ContainsGenericParameters is true**. at System.RuntimeType.CreateInstanceCheckThis() 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.Workflow.ComponentModel.Compiler.XomlCompilerHelper.InternalCompileFromDomBatch(String[] files, String[] codeFiles, WorkflowCompilerParameters parameters, WorkflowCompilerResults results, String localAssemblyPath)
Thanks,
T
Your type is being instantiated via Reflection. Whatever code is doing the instantiation doesn’t know how to instantiate a type with Generic parameters. It therefore throws an Exception.
Unfortunately, there’s really nothing you can do if you want to use
MyActivityBase<T>directly. You might be able to get by using concrete child implementations of your base class though (something likepublic class MyActivityString : MyActivityBase<string>)