🚑 🆘 [FirstAid] Migration to Windows target Framework - Missing Microsoft.Activities.Extensions package - Dictionary Activities

Introduction

When changing from Windows Legacy to Windows target framework the package: Microsoft.Activities.Extensions is no longer available. This package offered a few Activities for working with Dictionaries.

grafik

Issue

As the package is not available, so also the offered activities are no longer available and alternate handling is needed.

Workaround

Instead of using the activities from above, the same result can be achieved with the following options, mostly done on .Net API base.

Initialization

Example Case: myDict - a String, String Dictionary

Default Value

Assign Activity:

grafik
myDict = new Dictionary(Of String, String)

Build a Dictionary with initial entries

Usage of an Assign Activity for initialization and pre-population:
grafik

New Dictionary(Of String, String) From {
  {"ES","Spain"},
  {"AT", "Austria"}
}

Replacements

Add to Dictionary

Usage of an Assign Acitivty:
grafik
The value “France” will be added under the key “FR”

Get From Dictionary

Using an Assign Activity and retrieving the value for the particular key
grafik

Key exists in dictionary

Direct: myDict.ContainsKey("FR") - will return a boolean value
Assign Acitvity:
grafik
hasKey = myDict.ContainsKey("FR")

Value exists in dictionary

Direct: myDict.ContainsValue("France") - will return a boolean value
Assign Acitvity:
grafik
hasValue = myDict.ContainsValue("France")

Remove from dictionary - using the Key

Removing a dictionary item by using the particular key value
Direct Approach: myDict.Remove("FR") - will return a boolean value indicating if the removal was done or not, as the item with this key was not present
grafik
wasRemoved = myDict.Remove("FR")

Clear Dictionary

Option with Invoke method:

grafik
Kindly note: when using the Clear() method of the dictionary the original object instance is kept

Option with Assign Activity

will overwrite with a new empty dictionary
myDict = new Dictionary(Of String, String)

Others

Count Dictionary:

Direct usage: myDict.Count - will return an Int32 value
Assign Activity:
grafik

Conclusion

  • The lack of the formerly offered activities can be solved by rewriting them into a code approach
  • For further or special tasks can be fallen back on additional possibilities like e.g. LINQ

Documentation

Recommendations - Migration help

About the FirstAid Series

The first aid series offers various instructions on how to tackle a difficulty with the first steps

Questions

For questions on your specific case open a new topic and get individual support.

3 Likes