locked
Name 'variable name' is not declared exception in IF activity RRS feed

  • Question

  • Hi,



    I'm trying out WCF Workflow Service application. I created a variable customer and retrieved customer data from database but when I add IF activity following error happens:

    When I put customer <> Nothing into condition I get an error "Compiler error(s) encountered processing expression "customer <> Nothing". Name 'customer' is not declared."

    But when I put customer.Equals(Nothing) no error is displayed

    What can I be doing wrong. I don't know VB well so maybe I'm using the syntax incorrectly?



    P.S. By the way is/will be C# supported?
    Friday, April 16, 2010 8:38 AM

Answers

  • Hi,

    At this time, VB is used for Workflow expressions, whether the project is VB or C#, and I am not aware of any plans to allow the use of C# in the expressions.

    The <> operator in VB is not the correct way to test if an object is Nothing, you can use the Is keyword:

    customer Is Nothing

    or

    Not customer Is Nothing

    Using your method, if the customer is Nothing then there is no customer object on which to invoke the Equals method (it passes validation but when you run the workflow will terminate with an object not set exception)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Friday, April 16, 2010 2:37 PM

All replies

  • Hi,

    At this time, VB is used for Workflow expressions, whether the project is VB or C#, and I am not aware of any plans to allow the use of C# in the expressions.

    The <> operator in VB is not the correct way to test if an object is Nothing, you can use the Is keyword:

    customer Is Nothing

    or

    Not customer Is Nothing

    Using your method, if the customer is Nothing then there is no customer object on which to invoke the Equals method (it passes validation but when you run the workflow will terminate with an object not set exception)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

    Friday, April 16, 2010 2:37 PM
  • Just in case, make sure that the context where you are trying to use the variable, the IF activity mentioned above, is covered by the  scope  defined on the variable declaration.

     

     

    Friday, April 16, 2010 2:44 PM