Unable to assign a dictionary entry to a dictionary

Hi,

I want to create a dictionary (lets call it “dictionary1”) of type <String, Dictionary2>, with “Dictionary2” being also a dictionary, of type <Int32, HashSet>, with “HashSet” being a set of strings.

I successfully created all three variables and initialized each with the proper type.

I am able to fill the HashSet using the Invoke Method with the MethodName “Add”.

I am able to assign it to an entry of my Dictionary2 by simply doing an assignment using the Assign activity, as expected, this way:

dictionary2(1234) = myHashSet

Nevertheless, when I try to assign it to my dictionary1 the same way, that is,

dictionary1("whateverkey") = dictionary2

Studio complains with an error of the type “Cannot assign from type ‘System.Object’ to type ‘System.Collections.Generic.Dictionary2[System.Int32,System.Collections.Generic.HashSet1[System.String]]’ in Assign activity ‘Assign’.” (btw, what a hassle to have to type this by hand because there’s no way to copy&paste the actual error from Studio)

I’ve tried to change the variable type of dictionary1 from Dictionary<String,Dictionary<Int32,HashSet>> to merely Dictionary<String,Object> (thinking of casting the dictionary element when later I want to use it or whatever), but it complains with exactly the same error.

To provide some proof of concept I’m attaching some screenshots.

The dictionary variables are properly initialized:

Captura de pantalla 2023-12-05 103044

And this is where I’m doing the assignment:

No problem assigning the hashset to the dictionary:

Can you try to remove the error triggering variables from the “Variables” pane and readd them as proper types (not as Object)?

Hi, @efelantti ,

I don’t get what you mean. In the Variables pane they are already being set with the proper type, as you can see in the 2nd screenshot.

This is so stupid on the Studio side.

By chance, by copying the activity, then pasting it by mistake in Notepad++, I realized it’s not of the proper type I defined:

<?xml version="1.0" encoding="utf-16"?><ClipboardData Version="1.0" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation" xmlns:scg="clr-namespace:System.Collections.Generic;assembly=System.Private.CoreLib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><ClipboardData.Data><scg:List x:TypeArguments="x:Object" Capacity="1"><p:Assign x:Name="__ReferenceID0" VirtualizedContainerService.HintSize="434,83"><p:Assign.To><p:OutArgument x:TypeArguments="scg:Dictionary(x:Int32, scg:HashSet(x:String))">[diccionariDnisAnysMesos(dniActual)]</p:OutArgument></p:Assign.To><p:Assign.Value><p:InArgument x:TypeArguments="x:Object">[diccionariAnysMesos]</p:InArgument></p:Assign.Value></p:Assign></scg:List></ClipboardData.Data><ClipboardData.Metadata><scg:List x:TypeArguments="x:Object" Capacity="4"><scg:List x:TypeArguments="x:Object" Capacity="1"><x:Reference>__ReferenceID0</x:Reference></scg:List></scg:List></ClipboardData.Metadata></ClipboardData>

See the

<p:OutArgument x:TypeArguments=“scg:Dictionary(x:Int32, scg:HashSet(x:String))”>[diccionariDnisAnysMesos(dniActual)]</p:OutArgument></p:Assign.To><p:Assign.Value><p:InArgument x:TypeArguments=“x:Object”>[diccionariAnysMesos]</p:InArgument>

part?

This is, for sure, another of the stupid Studio bugs.

While writting this, I recreated the Assign activity and now it works.

Omg.

This software is far from being ready for production.

Sometimes this happens in Studio unfortunately :frowning: Especially in Assign activity.
Just cleaning both sides of Assign and re-entering usually helps. But you are right that it’s a bit frustrating.

Good luck!