ActivityLoad Method

MS Activities Extensions

Collapse image Expand Image Copy image CopyHover image
Loads loose XAML and pre-loads the assemblies to ensure correct CLR binding

Namespace: Microsoft.Activities.Extensions
Assembly: Microsoft.Activities.Extensions (in Microsoft.Activities.Extensions.dll) Version: 2.0.6.9 (2.0.6.9)

Syntax

C#
public static Activity ActivityLoad(
	string activityXaml,
	IList<string> assemblies
)
Visual Basic
Public Shared Function ActivityLoad ( _
	activityXaml As String, _
	assemblies As IList(Of String) _
) As Activity
Visual C++
public:
static Activity^ ActivityLoad(
	String^ activityXaml, 
	IList<String^>^ assemblies
)

Parameters

activityXaml
Type: System..::..String
The activity xaml.
assemblies
Type: System.Collections.Generic..::..IList<(Of <(<'String>)>)>
The assemblies.

Return Value

A DynamicActivity

Remarks

ActivityXamlServices.Load will load referenced assemblies using only the assembly name found in the XAML file. The default behavior stores only partial names for references. This means that when the assembly is loaded it will load with a partial name which could result in an unexpected version or entirely different assembly being loaded. As an alternative you can use the <qualifyAssembly> element in your config file to ensure the correct assembly is loaded

Examples

A class that runs loose XAML with an XamlAssemblyResolutionOption
CopyC#
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LooseXamlExample.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Activities;
using System.Activities.XamlIntegration;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Xaml;

using Microsoft.Activities.Extensions;

/// <summary>
/// Loose XAML Example
/// </summary>
// ReSharper disable CheckNamespace
public class LooseXamlExample
// ReSharper restore CheckNamespace
{
    #region Public Methods and Operators

    /// <summary>
    /// Returns a list of assemblies
    /// </summary>
    /// <returns>
    /// The list of assemblies
    /// </returns>
    public static IList<string> GetWorkflowLooseReferencedAssemblies()
    {
        // Create a list of activities you want to reference here
        var list = new List<string>
            {
                "ActivityLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c18b97d2d48a43ab", 
                Assembly.GetExecutingAssembly().GetName().FullName
            };

        // Add the standard list of references
        list.AddRange(StrictXamlHelper.StandardCSharpReferencedAssemblies);
        return list;
    }

    /// <summary>
    /// Invokes the loose xaml
    /// </summary>
    /// <param name="resolutionOption">
    /// The resolution option.
    /// </param>
    /// <exception cref="ArgumentOutOfRangeException">
    /// The option is unknown
    /// </exception>
    public static void InvokeLooseXaml(XamlAssemblyResolutionOption resolutionOption)
    {
        Console.WriteLine();
        Console.WriteLine("Loose XAML");
        try
        {
            switch (resolutionOption)
            {
                case XamlAssemblyResolutionOption.VersionIndependent:
                    WorkflowInvoker.Invoke(ActivityXamlServices.Load("WorkflowLoose.xaml"));
                    break;
                case XamlAssemblyResolutionOption.FullName:

                    // This will ensure the correct assemblies are loaded prior to loading loose XAML
                    WorkflowInvoker.Invoke(
                        StrictXamlHelper.ActivityLoad("WorkflowLoose.xaml", GetWorkflowLooseReferencedAssemblies()));
                    break;
                default:
                    throw new ArgumentOutOfRangeException("resolutionOption");
            }
        }
        catch (XamlObjectWriterException ex)
        {
            Console.WriteLine("Error loading loose xaml {0}", ex.Message);
        }
        catch (FileNotFoundException fileNotFoundException)
        {
            Console.WriteLine("Could not find assembly {0}", fileNotFoundException.FileName);
        }
        catch (FileLoadException fileLoadException)
        {
            Console.WriteLine("Could not load assembly {0}", fileLoadException.FileName);
        }
    }

    #endregion
}

See Also