Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ran into an identical issue working with non-dynamic activities and have now checked what is required to get this to work:</p> <h3>Summary</h3> <ol> <li><p>Add a reference to <code>System.Xaml</code></p></li> <li><p>Move <code>MailAddress</code> to a different namespace.</p></li> <li><p>Add some information to the <code>Dynamic Activity</code> about where your classes are coming from:</p></li> </ol> <pre><code>var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); var namespaces = new List&lt;string&gt; { typeof(MailAddress).Namespace }; TextExpression.SetReferencesForImplementation(dynamicActivity, new AssemblyReference { Assembly = typeof(MailAddress).Assembly }); AttachablePropertyServices.SetProperty(dynamicActivity, impl, namespaces); </code></pre> <p>To get at this answer I needed to dig around in the <code>TextExpressionCompiler</code> source so there might be something a lot more elegant.</p> <hr> <h3>Non-Dynamic Activities</h3> <p>If you are not using dynamic activities the call to <code>CompileExpressions</code> would change as described here: <a href="http://msdn.microsoft.com/en-us/library/jj591618.aspx">http://msdn.microsoft.com/en-us/library/jj591618.aspx</a>.</p> <p>Adding information to the activity would be modified by removing the "ForImplementation" parts:</p> <pre><code>var impl = new AttachableMemberIdentifier(typeof(TextExpression), "Namespaces"); var namespaces = new List&lt;string&gt; { typeof(MailAddress).Namespace }; TextExpression.SetReferences(nonDynamicActivity, new AssemblyReference { Assembly = typeof(MailAddress).Assembly }); AttachablePropertyServices.SetProperty(nonDynamicActivity, impl, namespaces); </code></pre> <hr> <h3>Working code</h3> <pre><code>using System; using System.Activities; using System.Activities.Expressions; using System.Activities.Statements; using System.Activities.XamlIntegration; using System.Collections.Generic; using System.Linq; using System.Xaml; using ExternalNamespace; using Microsoft.CSharp.Activities; namespace CSharpExpression { class Program { static void Main() { var errorCodeWorkflow = new DynamicActivity { Name = "MyScenario.MyDynamicActivity3", Properties = { new DynamicActivityProperty { Name = "Address", Type = typeof(InArgument&lt;MailAddress&gt;), }, }, Implementation = () =&gt; new WriteLine { Text = new CSharpValue&lt;String&gt; { ExpressionText = "\"MyDynamicActivity \" + Address.DisplayName" } } }; var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); var namespaces = new List&lt;string&gt; { typeof(MailAddress).Namespace }; TextExpression.SetReferencesForImplementation(errorCodeWorkflow, new AssemblyReference { Assembly = typeof(MailAddress).Assembly }); AttachablePropertyServices.SetProperty(errorCodeWorkflow, impl, namespaces); CompileExpressions(errorCodeWorkflow); WorkflowInvoker.Invoke(errorCodeWorkflow, new Dictionary&lt;String, Object&gt; { { "Address", new MailAddress { DisplayName = "TestDisplayName" } } }); } static void CompileExpressions(DynamicActivity dynamicActivity) { var activityName = dynamicActivity.Name; var activityType = activityName.Split('.').Last() + "_CompiledExpressionRoot"; var activityNamespace = string.Join(".", activityName.Split('.').Reverse().Skip(1).Reverse()); var settings = new TextExpressionCompilerSettings { Activity = dynamicActivity, Language = "C#", ActivityName = activityType, ActivityNamespace = activityNamespace, RootNamespace = "CSharpExpression", GenerateAsPartialClass = false, AlwaysGenerateSource = true, ForImplementation = true }; var results = new TextExpressionCompiler(settings).Compile(); if (results.HasErrors) { throw new Exception("Compilation failed."); } var compiledExpressionRoot = Activator.CreateInstance(results.ResultType, new object[] { dynamicActivity }) as ICompiledExpressionRoot; CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(dynamicActivity, compiledExpressionRoot); } } } namespace ExternalNamespace { public class MailAddress { public String Address { get; set; } public String DisplayName { get; set; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload