How to implement guide with converting anonymous types to dynamic objects in c# 10 using reflection
I'm trying to convert an anonymous type to a dynamic object using reflection in C# 10, but I'm working with issues where the properties are not accessible as expected. Here's the scenario: I'm fetching data from a database and projecting it into an anonymous type. When I try to convert it to a dynamic object, I receive a `RuntimeBinderException` indicating that the property does not exist. Here's the code I am using: ```csharp var results = from user in context.Users where user.IsActive select new { user.Id, user.Name, user.Age }; foreach (var result in results) { var dynamicObject = ConvertToDynamic(result); Console.WriteLine(dynamicObject.Name); } public dynamic ConvertToDynamic(object anonymousObject) { var expando = new System.Dynamic.ExpandoObject() as IDictionary<string, Object>; var properties = anonymousObject.GetType().GetProperties(); foreach (var property in properties) { expando.Add(property.Name, property.GetValue(anonymousObject)); } return expando; } ``` The behavior I am receiving is `System.Dynamic.RuntimeBinderException: 'want to dynamically invoke method 'Name' on the instance of type 'System.Dynamic.ExpandoObject'`. I have confirmed that the properties exist in the anonymous object. I tried casting the dynamic object to `IDictionary<string, object>` before accessing the properties, but it still throws an exception. I've also checked the project settings to ensure that dynamic types are properly supported, and I am indeed targeting .NET 6. Am I missing something in the conversion process, or is there a better way to handle this in C# 10? Any insights would be greatly appreciated. I'm working on a service that needs to handle this. Is there a better approach?