title: DynamicActivity - How to invoke a workflow that stored in Database?
body: <p>This is proof of concept project - The goal is to create an application that receive some system wide events and based on some business rules invokes a specific workflow.</p>
  
  <p>The workflows are created separately and the xaml source is stored in a database.</p>
  
  <p>Following is the code that used to invoke the workflow:</p>
  
  <pre><code>public void RaiseEvent(IEvent e, IEventData eventData)
  { 
  
      var typeName = e.GetType().FullName;
  
      // Query Db for all workflows for the event
      var repo = new WorkflowRepository();
  
      var workflows = repo.GetActiveWorkflowsByEvent(typeName);
  
      foreach (var wf in workflows)
      {
  
          var condition =   
   ConditionEvaluator.PrepareCondition(wf.Condition.Expression, eventData);
  
          var okToStart = ConditionEvaluator.Evaluate(condition);
          if (okToStart)
          {
  
             // Next line is throwing an exeption
              object o = XamlServices.Parse(wf.WorkflowDefinition.Expression);
  
  
              DynamicActivity da = o as DynamicActivity;
  
              WorkflowInvoker.Invoke(da,  
                     new Dictionary&lt;string, object&gt;   
                         {{ "EventData", eventData }});                   
  
  
          }
  
      }
  </code></pre>
  
  <p>We have created very simple workflow that runs without problems on its own. But when xaml is being loaded using XamlService.Parse it throw following exception:</p>
  
  <pre><code>System.Xaml.XamlObjectWriterException was unhandled
    Message='No matching constructor found on type 'System.Activities.Activity'.   
  You can use the Arguments or FactoryMethod directives to construct this type.' 
  Line number '1' and line position '30'.
  </code></pre>
  
  <p>Any idea what is wrong?
  Thank you.</p>