title: Can't access to internal property by reflection
body: <p>I have an <code>extension</code> :</p>
  
  <pre><code> public static T GetPrivatePropertyValue&lt;T&gt;(this object obj, string propName)
          {
              if (obj == null) throw new ArgumentNullException("obj");
              PropertyInfo pi = obj.GetType().GetProperty(propName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
              if (pi == null) throw new ArgumentOutOfRangeException("propName", String.Format("Property {0} was not found in Type {1}", propName, obj.GetType().FullName));
              return (T)pi.GetValue(obj, null);
          }
  </code></pre>
  
  <p>and I'm trying to use it as:</p>
  
  <pre><code>menuItem.GetPrivatePropertyValue&lt;RadMenuItem&gt;("ParentItem");
  </code></pre>
  
  <p>but I get an error at:</p>
  
  <pre><code>    return (T)pi.GetValue(obj, null);
  </code></pre>
  
  <p>which is:</p>
  
  <pre><code>    (T)pi.GetValue(obj, null)   'pi.GetValue(obj, null)' threw an exception of type 'System.MethodAccessException'  Telerik.Windows.Controls.RadMenuItem
  </code></pre>
  
  <p><code>menuItem</code> is an instance of <code>Telerik.Windows.Controls.RadMenuItem</code> class</p>
  
  <p>and the field I want is </p>
  
  <pre><code>internal RadMenuItem ParentItem
  {
      get
      {
          return ItemsControl.ItemsControlFromItemContainer(this) as RadMenuItem;
      }
  }
  </code></pre>
  
  <p>What is wrong my code? It's because this property is internal?</p>
  
  <pre><code>EDIT
  </code></pre>
  
  <p>This is my stacktrace:</p>
  
  <pre><code>{System.MethodAccessException: Attempt by method 'MyApp.Extensions.GetPrivatePropertyValue&lt;System.__Canon&gt;(System.Object, System.String)' to access method 'Telerik.Windows.Controls.RadMenuItem.get_ParentItem()' failed.
     at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, RuntimeMethodHandleInternal method, RuntimeType parent, UInt32 invocationFlags)
     at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj, IRuntimeMethodInfo method, RuntimeType parent, UInt32 invocationFlags)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
     at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
     at MyApp.Extensions.GetPrivatePropertyValue[T](Object obj, String propName)
     at MyApp.Calendar.OnContextMenuItemClick(Object sender, RadRoutedEventArgs e)}
  </code></pre>
  
  <p>And maybe it is important: technology of my application is <code>Silverlight 4</code></p>