Workflow designer rehosting and user defined types RRS feed

  • General discussion

  • I'm rehosting workflow designer, and I want to use my custom types as variables of the workflow. At first I couldn't get my types to be shown in the "Browse and Select a .Net Type" Window. I maneged to do that by loading assembly to AppDomain:


    But now when I want to assign a property of a variable which is of type from my assembly I get the message: Compiler error(s) encountered processing expression "variable1.Attribute1" Type "BusinessObject1" is not defined.

    [BusinessObject1] is a type defined in my custom assembly.

    Does any one know how to "add" an assembly to workflow compiler?


    Monday, November 1, 2010 3:47 PM

All replies

  • The problem is the way I load the assembly if i load it in this way:


    everything works fine. But I can't really use this in my application because it's XBAP application and I would have to save assembly bytes array to a temp location and load it from disk - but to do that I would have to elevate application credentials and i don't want to do that. I couldn't find a way to use Assembly.LoadFrom to load from IsolatedStorage (if i could use IsolatedStorage I wouldn't have to elevate credentials).

    Does anyone have any ideas how to by pass those problems? it can be crazy - i'm desperate :)

    Tuesday, November 2, 2010 5:34 PM
  • Basically there's a magical setting which lists all of the Visual Basic namespaces which the Visual Basic compiler should pick up from your reference assemblies. This shows up as 'VisualBasicSettings' or 'VisualBasic.Settings' in the workflow XAML and is alluded to here in one of Cathy's posts.


    Googling around I found this snippet on Kushal's blog on creating expressions using code:

    VisualBasicSettings vbSettings = new VisualBasicSettings();
    vbSettings.ImportReferences.Add(new VisualBasicImportReference
            Assembly = requiredAssemblyName,
            Import = requiredNamespace

    mySimpleVar.Default = new VisualBasicValue<foo.fooClass>
           ExpressionText = "new foo.fooClass()",
             Settings = vbSettings


    (You should probably be able to achieve the similar effect manually using the Imports gadget found at the bottom of the designer, but I think you are interested in programmatic solutions?)


    Wednesday, November 3, 2010 5:24 AM
  • I have same scenario like what mentioned in this thread. I have my WF file present in the bin folder which I loading into rehosted WF designer. In the designer I am always getting error saying that my custom types are not known.

    I tried to load the assembly, tried teh VBSetting etc... but no luck.

    Please help...

    www.joyfulwpf.blogspot.com , www.silverlightedweb.blogspot.com, www.joymonscode.blogspot.com

    Monday, June 30, 2014 9:38 PM
  • I was able to resolve when I gave assembly name inside the XAML imports.

    Earlier code inside the workflow.xaml


    Modified to


    www.joyfulwpf.blogspot.com , www.silverlightedweb.blogspot.com, www.joymonscode.blogspot.com

    Tuesday, July 1, 2014 12:48 AM
  • Hi,

    I have faced the same problem with custom type and rehosted Workflow Designer. Tim Lovell-Smith's advice with VisualBasicSettings for VisualBasic Compiler Services is Ok, but the imports are dynamicaly changed while you're working in the designer. So it's necessary to refresh VisualBasicSettings imports every time the validation is called. I have made one method for prepare Visual Basic Settings. This method gets all imported namespaces and fills VB settings. Of course the method is not optimal, but functional.

    Here my functional code fragment:

    WorkflowDesigner workflowDesigner;

    private void AddVisualBasicSettings() { Log.Debug("Started AddVisualBasicSettings"); System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); var rootElement = (this.Designer.GetWorkflowDesignerRoot().GetCurrentValue() as System.Activities.ActivityBuilder).Implementation; Microsoft.VisualBasic.Activities.VisualBasicSettings vbs = Microsoft.VisualBasic.Activities.VisualBasic.GetSettings(rootElement); if (vbs == null) vbs = new Microsoft.VisualBasic.Activities.VisualBasicSettings(); var imports = this.Designer.Context.Items.GetValue<System.Activities.Presentation.Hosting.ImportedNamespaceContextItem>().ImportedNamespaces; var assemblies = this.Designer.Context.Items.GetValue<System.Activities.Presentation.Hosting.AssemblyContextControlItem>().AllAssemblyNamesInContext; foreach (var assemblyString in assemblies) { var assembly = System.Reflection.Assembly.Load(assemblyString); foreach (var import in imports) { if (vbs.ImportReferences.ToList().Any(i => i.Import == import)) continue; Type[] types = null; try { types = assembly.GetTypes(); foreach (var type in types) { string ns = type.Namespace; if (!string.IsNullOrEmpty(ns) && import == ns && !vbs.ImportReferences.ToList().Any(i => i.Import == import)) { var assemblyName = assembly.GetName().Name; vbs.ImportReferences.Add(new Microsoft.VisualBasic.Activities.VisualBasicImportReference { Import = ns, Assembly = assemblyName }); break; } } } catch (Exception) { } } } Microsoft.VisualBasic.Activities.VisualBasic.SetSettingsForImplementation(rootElement, vbs); stopWatch.Stop(); TimeSpan elapsedTime = stopWatch.Elapsed; Log.Debug("Finished AddVisualBasicSettings in {0} seconds", elapsedTime.TotalSeconds); }

    • Edited by TomasJakl Wednesday, July 16, 2014 12:12 PM
    Wednesday, July 16, 2014 12:09 PM