Custom workflow action always gots error RRS feed

  • Question

  • Hi all,

    I hope to make a custom action for workflow and could be used in SPD 2010. This action takes 2 paramter, one is string another is date to query the calendar and return a string from an event title. The code is like this:

    Imports System.Collections
    Imports Microsoft.SharePoint
    Imports Microsoft.SharePoint.UserCode
    Imports Microsoft.SharePoint.Workflow
    Namespace MyWorkflow.Actions
        Public Class CalendarQuery
            Public Function TestFunction(Context As SPUserCodeWorkflowContext, CalendarName As String, EventDate As Date) As Hashtable
                Dim htResult As New Hashtable(1)
                htResult.Add("Result", "Test")
                Return htResult
            End Function
        End Class
    End Namespace

    Then I made an Element file in the VS project as this

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
        <Action Name="Return value test"
                Category="Test Actions">
          <RuleDesigner Sentence="From calendar [%2] on date [%1] get OT rate and put into [%3]">
            <FieldBind Id="1" Field="EventDate" DesignerType="ParameterNames" Text="OT Date"></FieldBind>
            <FieldBind Id="2" Field="CalendarName" DesignerType="ParameterNames" Text="Calendar Name"></FieldBind>
            <FieldBind Id="3" Field="Result" DesignerType="ParameterNames" Text="Action Result"></FieldBind>
            <Parameter Name="__Context" Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext, Microsoft.SharePoint.WorkflowActions" Direction="In" DesignerType="Hide"/>
            <Parameter Name="EventDate" Type="System.DateTime, mscorlib" Direction="In" />
            <Parameter Name="CalendarName" Type="System.String, mscorlib" Direction="In" />
            <Parameter Name="Result" Type="System.String, mscorlib" Direction="Out" DesignerType="ParameterNames"/>

    The compile and deploy are succesfully finished. And the action is visible in SPD when making a list workflow. But the workflow always get error in the history, never complete.

    My main reference are:



    But these two articles have some conflict such as whether the function should be declared as 'Shared', which mean 'static' in c#.

    Does any one has the idea about how to modify the code and the element file to make it work?

    Alex Du

    Sunday, June 10, 2012 11:06 AM


  • Generally, this problem is caused by the compiler difference between C# and VB.NET.

    The solution is: add a Shared Sub New for the VB class.

    Reason: a C# class contains a static method will be mark a flag 'beforefieldinit' by the compiler, and visible in ILDasm. But VB.NET compiler doesn't do this. So the runtime try to locate and invode the static constructor, Shared Sub New in VB.NET, at first before invoke the function declared in Element.xml and got the error like "Activation did not throw an exception but it returned null".

    I spent 4 days on this issue, and finally solved.

    Alex Du

    • Marked as answer by Alex Du Thursday, June 14, 2012 10:19 AM
    Thursday, June 14, 2012 10:19 AM