locked
Activity library vs. Class Library: Validator fails in Activity Library RRS feed

  • Question

  • I'm attempting to create a simple validator that ensures that a path has been supplied in an activity. When I create this in an Activity library, the code won't compile because AT COMPILE TIME, an error occurs because the path property is empty. When I take the same two classes and put them in a Class Library, it all works fine (and the activity works as expected). I compared all the project settings, and simply couldn't find the difference. The code I'll post here is in VB, but the same exact thing happened in a C# Activity Library project vs. a Class Library project. I'd really like to be able to use an Activity Library project (I'm writing courseware, and would like to things "the right way", but couldn't get the demo to work there.) I've attached the two classes, simplified as much as possible. Has anyone seen this behavior? Any suggestions on how to get this to work in an Activity Library?

    Thanks! -- Ken

    ==========================

    ' LoadTextFileActivity class

    Imports System.ComponentModel

    Imports System.ComponentModel.Design

    Imports System.Workflow.ComponentModel

    Imports System.Workflow.ComponentModel.Design

    Imports System.Workflow.ComponentModel.Compiler

    Imports System.Drawing

    Imports System.IO

     

    <ActivityValidator(GetType(LoadTextFileActivityValidator))> _

    Public Class LoadTextFileActivity

      Inherits Activity

     

      Public Shared FileNameProperty As DependencyProperty = _

       DependencyProperty.Register("FileName", GetType(String), GetType(LoadTextFileActivity), New PropertyMetadata(DependencyPropertyOptions.Metadata))

     

      <Description("Full name of the file to load.")> _

      <Category("Behavior")> _

      <Browsable(True)> _

      <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _

      Public Property FileName() As String

        Get

          Return (CType((MyBase.GetValue(LoadTextFileActivity.FileNameProperty)), String))

        End Get

        Set(ByVal Value As String)

          MyBase.SetValue(LoadTextFileActivity.FileNameProperty, Value)

        End Set

      End Property

     

      Public Shared FileTextProperty As DependencyProperty = _

        DependencyProperty.Register("FileText", GetType(String), GetType(LoadTextFileActivity))

      <Description("Retrieve the text from the specified file.")> _

      <Browsable(True)> _

      <Category("Behavior")> _

      <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _

      Public Property FileText() As String

        Get

          Return (CType((MyBase.GetValue(LoadTextFileActivity.FileTextProperty)), String))

        End Get

        Private Set(ByVal Value As String)

          MyBase.SetValue(LoadTextFileActivity.FileTextProperty, Value)

        End Set

      End Property

     

      Protected Overrides Function Execute( _

       ByVal executionContext As ActivityExecutionContext) _

       As ActivityExecutionStatus

     

        If FileName IsNot Nothing Then

          FileText = File.ReadAllText(FileName)

        End If

        Return ActivityExecutionStatus.Closed

      End Function

    End Class

    ==========================

    ' LoadTextFileActivityValidator class

    Imports System.Workflow.ComponentModel.Compiler

    Imports System.Workflow.ComponentModel

    Imports System.IO

    Imports System.Text.RegularExpressions

     

    Public Class LoadTextFileActivityValidator

      Inherits ActivityValidator

     

      Public Overrides Function Validate( _

       ByVal manager As ValidationManager, ByVal obj As Object) As ValidationErrorCollection

     

        Dim activity As LoadTextFileActivity = TryCast(obj, LoadTextFileActivity)

     

        If activity Is Nothing Then

          Throw New InvalidOperationException("The parameter wasn't of the correct type.")

        End If

     

        Dim errors As ValidationErrorCollection = MyBase.Validate(manager, obj)

     

        If String.IsNullOrEmpty(activity.FileName) Then

          errors.Add(ValidationError.GetNotSetValidationError("FileName"))

        End If

        Return errors

      End Function

     

     

    End Class

     

    Thursday, March 8, 2007 5:10 PM

Answers

  • Sorry for the multiple posts -- I didn't see the item appear, so posted again. Sorry again...
    Thursday, March 8, 2007 8:32 PM