I\'m trying to write a simple object to Dictionary converter like below:
public static class SimplePropertyDictionaryExtensionMethods
{
public static IDi
Remove BindingFlags.GetProperty
This is used to get a property value when using InvokeMember, it does not specify that you want a read only property returned.
EDIT: The problem may actually be with the propertyInfo.GetGetMethod() - Try using one of the following (I have only ever used the first one):
var value = propertyInfo.GetValue(input, null);
var value = propertyInfo.GetGetMethod().Invoke(input, null);
I guess that your ToSimplePropertyDictionary method and the actual usage are in two separate assemblies. This is the source of your problem because the compiler generated class which is generated from an anonymous class is internal. That is why you get the MethodAccessException exception. So you need to use the InternalsVisibleToAttribute to make it work. This SO question contains more info about internal types and reflection.