'.net 6 migration JsonElement to dynamic

I come from .net core 2.1 and after migration to .net 6 i got different behavior.

I have json in my RabbitMQ. After cunsume new message i deserialize to class with field List<dynamic>

class msg{
   public string Name {get;set;}
   public int Old {get;set;}
   ... other fiedls 
   public List<dynamic> list {get;set;}
}

Working code from 2.1 now throw error

    foreach (var i in msg.list)
    {
        switch ((VariantEnum)i.variant)

In debug i found that now "var i" is typeof JsonElement

How i can in .net 6 use dynamic like before ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source