none
How can I get the properties of a class (.dll not .net)? RRS feed

  • Question

  • As posted in the title, I'm getting the properties of a class or an interface, like in the simple code below:

    MapControl map = new MapControl();  //A class of "ESRI.ArcGIS".
            foreach(var p in map.GetType().GetProperties()) {
    
            }

    It throws the below exception:

    System.Runtime.InteropServices.COMException was unhandled
      HResult=-2147221231
      Message=Retrieving the COM class factory for component with CLSID {C552EA94-6FBB-11D5-A9C1-00104BB6FC1C} failed due to the following error: 80040111 ClassFactory Unable to supply the requested class (Exception from HRESULT: 0x80040111 (CLASS_E_CLASSNOTAVAILABLE)).
      Source=ReadProperties
      ErrorCode=-2147221231
      StackTrace:
           at ReadProperties.MainForm.MainForm_Load(Object sender, EventArgs e) in E:\Test\ReadProperties\ReadProperties\MainForm.cs:line 19
           at System.Windows.Forms.Form.OnLoad(EventArgs e)
           at System.Windows.Forms.Form.OnCreateControl()
           at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
           at System.Windows.Forms.Control.CreateControl()
           at System.Windows.Forms.Control.WmShowWindow(Message& m)
           at System.Windows.Forms.Control.WndProc(Message& m)
           at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
           at System.Windows.Forms.ContainerControl.WndProc(Message& m)
           at System.Windows.Forms.Form.WmShowWindow(Message& m)
           at System.Windows.Forms.Form.WndProc(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
           at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
           at System.Windows.Forms.Control.set_Visible(Boolean value)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           at System.Windows.Forms.Application.Run(Form mainForm)
           at ReadProperties.Program.Main() in E:\Test\ReadProperties\ReadProperties\Program.cs:line 15
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    So,Could something hold an idea about what to do? Thanks very much.

    Monday, October 7, 2013 12:18 AM

All replies

  • Hi Victor,

    Thanks for your posting.

    From your description, I know that you encounter some issues  when you  get the properties of a Map Control class. I think that map.GetType().GetProperties())  is wrong. you should map.GetType().InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[]) method.

    For more detailed information, you can refer Type.InvokeMember Method (String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])

    In addition,  there is a sample : “ How To Get Properties and Methods in Late Binding COM-Apps Like Excel “ that describes  in detail  how to Get Properties and method .It introduces  How to Get the Members, Properties and Methods  through   an  Excel sample  about  late Binding Com-Apps.

    Hope these help.


    Lilia Gong <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, October 7, 2013 9:51 AM
    Moderator