Coded workflow unable to use C# generics

I’m working on making a Coded_Workflow for my library, that should turn a QueueItem into a C# model. For this I want to use basic generics in C#.

public (T model, Exception ex) Execute<T>(QueueItem queueItem, T model) where T : new()
{
   Exception ex = null;
        
   // Set static QueueItem fields
   typeof(T).GetProperty("Id").SetValue(model, queueItem.Id);
   typeof(T).GetProperty("Reference").SetValue(model, queueItem.Reference);
            
   // Set dynamic QueueItem fields
   foreach (var property in typeof(T).GetProperties())
   {
      foreach (var header in queueItem.SpecificContent)
      {
         if (property.Name == header.Key)
         {
            property.SetValue(model, header.Value);
         }
      }
   }
        
   return (model, ex);
}

But when I try to run it, I get an error:

Unexpected error has occurred during the library compilation process:
The assembly compilation returned the following errors:
\Code\QueueItemToModel+QueueItemToModelActivity.cs(33,27): error CS0246: The type or namespace name ‘T’ could not be found (are you missing a using directive or an assembly reference?)

And a bunch more lines similar to the last one.


This is my test workflow


And here is my Import Arguments for my Invoke Workflow

Generics are absolutely supported, but not in an invoke-able workflow (as far as I know).

You can use your generic in a class in a coded source file however, and then use that in a normal workflow, so what you need is possible, you just need to tweak it abit.

Good feedback. I will try that and update this thread with my results

Alright. So it does work with a Coded Source file but not a Coded Workflow.

Hi Henrik,

Could you please mark this as resolved from the answer by @Jon_Smith

Thanks!