Switch Activity(String) with Contains- Getting Cannot infer a common type because more than one type is possible Error

Trying to use Switch activity in string format with Contains for 3 cases.
The logic I tried is

Where Environment is a variable.
According to the syntax-
If( txt=“path1”,“PATH1”, If( txt=“path2”,“PATH2”, If( txt=“path3”,“PATH3”, “Default” ) ) )

But am getting and error- Cannot infer a common type because more than one type is possible

For the switch, you simply just pass in the expression Environment variable

Hi @SanjanKaje777,

Welcome to community.

What exactly does Environment.Contains refer to?

If you have a variable called Environment, it may be conflicting with the function, you can do a test by changing it.

Regards,
MY

try to avoid Environment as Variable name as it is already existing as Class Name within VB.Net

lets assume a String Variable strCheckValue

Ensure that the switch TypeArgument is set to String

then use following Expression:

{"Test1","Test2","Test3"}.Where(Function (x) strCheckValue.Contains(x)).First()

feel free to harmonize it e.g. with ToUpper for the checks

I have already passed. And Environment as a variable i just used as a testing purpose. Tried with other variable names and i am getting the same error.

Environment as a variable i just used randomly for testing purpose. Tried with other variable names too instead of Environment and i am getting the same error.
I have tried with
If( TestVariable.Contains(“Test1”), “Test1”,
If( TestVariable.Contains(“Test2”), “Test2”,
If( TestVariable.Contains(“Test3”), “Test3”)
))
where TestVariable is a variable i passed as a string.
But got the same error.

your expression for switch case should look like this
image

1 Like

Explanation: you were missing 2 things.

  1. Line continuation character i.e. underscore at the end of the lines.
  2. Else part of last condition i.e. Test3 was missing.

This solution worked for me.
Added underscore in each line as you mentioned.
Thank you so much.

Great!
Please mark my post as solution :slight_smile:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.