none
Rehosted Designer: Using custom activities from dll

    Question

  • I adding to activities toolbar my custom activity, made in rehosted designer and compiled via msbuild.exe . Then I dragging it from toolbar to my workflow view. But when I try to compile or just run activity , which is using activity from the dll, there is the error. It cannot find type of needed activity in dll. Dll is in designer's executable folder.

    =Sorry for my english

    Tuesday, August 3, 2010 9:22 AM

Answers

  • If you start using custom activities from assembly X, which depends on assembly Y which depends on Z, in project P, I think you need to add assembly references to all of X,Y,Z to P.csproj, not just X.

    Tim

    • Marked as answer by Deadarius Tuesday, August 10, 2010 6:49 AM
    Thursday, August 5, 2010 6:01 PM
    Moderator

All replies

  • Could you provide more detail on how you are trying to compile or run the activity? Is it within the rehosted designer application, or are you launching the separate application? When you compile, are you passing the DLL to the compiler as a referenced assembly?
    Thanks,
    Tim

    Tuesday, August 3, 2010 10:32 AM
    Moderator
  • Hi Deadarius,

    As you i used rehosting and i code this to imports activities in my toolbox

    #region "Constructeurs"
    
    /// <summary>
    /// Constructeurs
    /// </summary>
    public MyWorkflowDesigner()
    {
      InitializeComponent();
      // Evenèneement sur chargement du control
      this.Loaded += new RoutedEventHandler(_Loaded);
    }
    
    #endregion
    
    #region "Chargement de la toolbox"
    
    /// <summary>
    /// Control chargé
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void _Loaded(object sender, RoutedEventArgs e)
    {
      // Enregistrement des metadata pour utiliser un Designer de Workflow
      new DesignerMetadata().Register();
    
      // Ajouter les icons manquant à la toolbox (icon des activités de base, non présent dans le framework)
      ActivitiesIconHelper.LoadToolboxIconsForBuiltInActivities();
    
      // Création de la toolbox
      ToolboxControl toolboxControl = new ToolboxControl();
    
      // Activité Custom présentes dans ce projet
      AddToolBoxCategory(toolboxControl, Properties.Resources.CustomToolbox, typeof(MyWorkflowDesigner).Assembly);
    
      // Activité de base
      AddToolBoxCategory(toolboxControl, Properties.Resources.BuiltinToolbox, typeof(Sequence).Assembly);
    
      // Ajout du control de la toolbox au control
      Grid.SetColumn(toolboxControl, 0);
      Grid.SetRow(toolboxControl, 0);
      Grid.SetRowSpan(toolboxControl, 2);
      this.DesignerGrid.Children.Add(toolboxControl);
    
      // Référence vers la tolbox pour possible utilisation externe
      m_ToolboxControl = toolboxControl;
    
      this.LoadWorkflowDesignerEmpty();
    }
    
    /// <summary>
    /// Ajout d'une catégorie à la toolbox avec ses controls
    /// </summary>
    /// <param name="toolboxControl"></param>
    /// <param name="categoryName"></param>
    /// <param name="assemblies"></param>
    private static void AddToolBoxCategory(ToolboxControl toolboxControl, String categoryName, params Assembly[] assemblies)
    {
      // Création d'une nouvelel category
      ToolboxCategory toolboxCategory = new ToolboxCategory(categoryName);
    
      // Filtre utilisé pour trouver les activité à wrapper
      Func<Assembly, IEnumerable<ToolboxItemWrapper>> getItems = assembly =>
        from type in assembly.GetTypes()
        where type.IsPublic
          && !type.IsNested
          && !type.IsAbstract
          && !type.ContainsGenericParameters
          && (typeof(Activity).IsAssignableFrom(type)
          || typeof(IActivityTemplateFactory).IsAssignableFrom(type))
        orderby type.Name
        select new ToolboxItemWrapper(type);
    
      // Requete sur la liste des controls pour trouver ceux qui seront utilisables
      List<ToolboxItemWrapper> query = assemblies
        .SelectMany(c => getItems(c))
        .ToList();
    
      if (query.Count > 0)
      {
        try
        {
          // Ajout des catégories à la toolbox
          query.ForEach(c => toolboxCategory.Add(c));
          
          // Ajout de la nouvelle catégorie à la toolbox
          toolboxControl.Categories.Add(toolboxCategory);
        }
        catch(Exception ex)
        {
          MessageBox.Show(
            ex.Message, 
            System.Windows.Forms.Application.ProductName, 
            MessageBoxButton.OK, 
            MessageBoxImage.Exclamation);
        }
      }
    }
    
    #endregion
    

    As you can see, i have a method to add ctivities to my toolbox : AddToolBoxCategory

    And i call it 2times to add 2 group in my toolbox. Activities are from 2 diferents assemblies. You could try something like this ;)


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Tuesday, August 3, 2010 12:01 PM
  • Ok, really, I just forgot to add my dll to <references> tag of my *.csproj. But I have another problem now. I used System.Windows.Forms in my custom activity. And when I adding custom activity to my new workflow, I getting an error from custom activity "Forms is not a member of Windows". I tried to import System.Windows.Forms in my rehosted designer, but nothing changed. Must I add System.Windows.Forms assembly and namespace into *.csproj of custom activity, when compiling it? If it is, then how can make my designer know about what references used in custom activity, when it compiles.
    Thursday, August 5, 2010 3:42 AM
  • Hi Deadarius,

    Did you import the presentation references ?

    • System.Activities.Presentation
    • PresentationFramework
    • PresentationCore

     


    Jérémy Jeanson MCP, MCTS http://blogs.codes-sources.com/JeremyJeanson/ (French or English spoken)
    Thursday, August 5, 2010 9:01 AM
  • If you start using custom activities from assembly X, which depends on assembly Y which depends on Z, in project P, I think you need to add assembly references to all of X,Y,Z to P.csproj, not just X.

    Tim

    • Marked as answer by Deadarius Tuesday, August 10, 2010 6:49 AM
    Thursday, August 5, 2010 6:01 PM
    Moderator
  • Can you explain why the following condition is used? Wouldn't this suppress custom activities with generics like ForEach<T> or AddToCollection<T> ?
    && !type.ContainsGenericParameters
    Monday, October 18, 2010 1:56 PM