none
Can not add custom activity which is not in exe directory to toolbox in my rehosted Designer

    Question

  • Hi,
    Below is c# code:
                string _AssemblyPath = AppDomain.CurrentDomain.BaseDirectory + @"ExtCustomActivity\";
                DirectoryInfo di = new DirectoryInfo(_AssemblyPath);
                FileInfo[] rgFiles = di.GetFiles("*.dll");
                foreach (FileInfo fi in rgFiles)
                {
                    Assembly asm = Assembly.LoadFrom(_AssemblyPath + fi.Name);
                    List<ToolboxItemWrapper> toolboxItemList = new List<ToolboxItemWrapper>();
                    foreach (Type type in asm.GetTypes())
                    {
                        if (type.IsSubclassOf(typeof(Activity)))
                        {
                            ToolboxItemWrapper tbItemWrapper = new ToolboxItemWrapper(type);
                            toolboxItemList.Add(tbItemWrapper);
                        }
                    }
                    if (toolboxItemList.Count > 0)
                    {
                        ToolboxCategory myActivities = new ToolboxCategory();
                        string[] categoryName = asm.FullName.Split(',');

                        myActivities.CategoryName = categoryName[0];

                        foreach (ToolboxItemWrapper tbItem in toolboxItemList)
                        {
                            myActivities.Tools.Add(tbItem);
                        }
                        toolbox.Categories.Add(myActivities);
                    }
    But program run at line: toolbox.Categories.Add(myActivities);, exception error message:FileNotFoundException was unhandled-"Could not load file or assembly 'CustomActivityLibraryTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies."
    How to resolve this  problem?

    Wednesday, February 10, 2010 3:59 AM

Answers

  • Hi Jimmy,

    This is happening because (implementation quirk):

    1) The assembly is loaded using LoadFrom
    2) The toolbox item wrapper internally converts the Type you passed it to a fully qualified type name string
    3) On drag+drop, the string is converted back to a type
    4) Since the assembly was loaded using LoadFrom, the type is not automatically resolvable
    5) No custom assembly resolver exists to save the day

    Ways I would recomment to workaround the problem is fix step 1 or step 5 -

    -use Assembly.Load instead
    or
    -keep using Assembly.LoadFrom, but add an assembly resolve event handler to your app domain.

    Please let me know if this works for you.
    Tim
    • Marked as answer by jimmy osem Thursday, February 11, 2010 4:07 PM
    • Unmarked as answer by jimmy osem Thursday, February 11, 2010 4:07 PM
    • Marked as answer by jimmy osem Thursday, February 11, 2010 4:27 PM
    Wednesday, February 10, 2010 7:46 PM

All replies

  • Hi Jimmy,

    This is happening because (implementation quirk):

    1) The assembly is loaded using LoadFrom
    2) The toolbox item wrapper internally converts the Type you passed it to a fully qualified type name string
    3) On drag+drop, the string is converted back to a type
    4) Since the assembly was loaded using LoadFrom, the type is not automatically resolvable
    5) No custom assembly resolver exists to save the day

    Ways I would recomment to workaround the problem is fix step 1 or step 5 -

    -use Assembly.Load instead
    or
    -keep using Assembly.LoadFrom, but add an assembly resolve event handler to your app domain.

    Please let me know if this works for you.
    Tim
    • Marked as answer by jimmy osem Thursday, February 11, 2010 4:07 PM
    • Unmarked as answer by jimmy osem Thursday, February 11, 2010 4:07 PM
    • Marked as answer by jimmy osem Thursday, February 11, 2010 4:27 PM
    Wednesday, February 10, 2010 7:46 PM
  • Hi Tim,
    Thanks for your reply!
    Now I solve this problem. I add C# code: AppDomain.CurrentDomain.AppendPrivatePath("ExtCustomActivity"); in the initialization. But this way needs directory "ExtCustomActivity" is under the exe directory, it can not in
    anyplace. 

    Jimmy
    Thursday, February 11, 2010 4:27 PM