Unable to create new case in Switch activity

Studio version: 26.0.192-cloud.22823
OS: Windows

Steps to reproduce:

  1. Create a Switch activity with TypeArgument = String
  2. Click “Add Case” button

Error:
System.Exception: Object reference not set to an instance of an object
at UiPath.PackageActivitiesMetadata.ViewModels.SwitchViewModel`1.CreateDefaultItemForProperty(String propertyName)

Workaround: manually add cases via XAML using x:Key=“CaseName”

Hi @Vinh_Quang_Tran1,

Welcome to the community.

I checked and I’m able to add the cases. Could you please confirm if you’ve added the expression before creating the cases?

Thanks

Welcome to the community!

Have you tried to erase and readd the switch?, Do you have this error as well if you try with the flow switch?

Activities - Flow Switch

@Vinh_Quang_Tran1

This looks like a Studio designer issue in the 26.0 cloud version, not a problem with your workflow.

Why this happens

When you change the Switch activity TypeArgument to String and click Add Case, Studio tries to auto-create a new case entry in the UI. In this version, that process is failing internally (null reference in SwitchViewModel), so it throws the error instead of adding the case.

So basically:

  • Switch<String> is valid and supported
  • But the designer UI is breaking while adding cases
  • Runtime/XAML itself still works fine

How to resolve (workaround)

Until UiPath fixes this in a patch, you can do the following:

  1. Open the .xaml file in a text editor (Notepad++ or similar).
  2. Locate your Switch activity.
  3. Manually add cases using x:Key.

Example:

<ui:Switch x:TypeArguments="x:String" Expression="[yourVariable]">  <ui:Switch.Cases>    <x:String x:Key="Case1">Case1</x:String>    <x:String x:Key="Case2">Case2</x:String>  </ui:Switch.Cases></ui:Switch>
  1. Save the file.
  2. Reopen it in Studio.

After that, you can continue building logic inside each case normally.

Additional note

If possible, also try updating Studio to the latest patch version, as this looks like a regression that may already be fixed.