I'm developing a Blazor app where, in the function section of one of my views, I have:
var dict = await Http.GetJsonAsync<Dictionary<Node, Decimal>>($"api/Home/test");
Node is a custom object I've defined. Then in the corresponding controller action, I have:
[HttpGet("[action]")]
public Dictionary<Node, decimal> test()
{
var dict = new Dictionary<Node, decimal>();
var node = new Node();
dict[node] = 10m;
return dict;
}
When I try to fetch the dictionary in this way, I see this error in the console:
WASM: [System.ArgumentException] The value "App.Shared.Node" is not of type "App.Shared.Node" and cannot be used in this generic collection.
If I new up one of these dictionaries, but put nothing it it, I don't see this error. I suspect that something about the fact of using my Node objects as keys is getting me in trouble, but it's not clear to me why this shouldn't work. (I certainly have no problem using these dictionaries elsewhere in my application.)