none
How to get an instance of object created from assebly loaded in application

    Question

  • My assembly that is used at various times in an application needs to get a reference to instance of an object that is created by an assembly that is loaded by an application at start up. I am not sure how to go about to code to do this. If anyone has a suggestion or may a link to some source code that has an example on how to do this I would be greatful.


    steven frierdich
    Thursday, January 19, 2012 3:17 AM

Answers

  • Well thats just it. I do not control the code at start up. It seems that a referece to the object in the assembly created would be automatically stored somewhere by the application, and that a reference to the object could be obtained through the appdomain object or something like that.

    Like when a form is create a reference can be obtain to it through the Application.OpenForms


    steven frierdich

    Application.OpenForms only works because the Application class is doing what I suggested - it's storing forms (on show) in this static collection.

     

    Reflection will allow you to investigate types, but unless you know of a place where this object is stored, there will be no way to discover the object reference directly.  There is no "global" list of object handles you could use to get an object reference - you'd need to have some other means of attaching to it.

     

    What are you trying to do?  What type of object is this?  Depending on what the actual object is, and whether you have good type information, there may be another approach.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, January 23, 2012 4:31 PM

All replies

  • You will need to store that instance somewhere that your routine can access, if you need to get a handle to that instance.

     

    When the object is created (at startup), store the instance in some class where your assembly can gain access to it.  You'd then reference it as needed.

     


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Thursday, January 19, 2012 4:04 AM
  • Well thats just it. I do not control the code at start up. It seems that a referece to the object in the assembly created would be automatically stored somewhere by the application, and that a reference to the object could be obtained through the appdomain object or something like that.

    Like when a form is create a reference can be obtain to it through the Application.OpenForms


    steven frierdich
    Sunday, January 22, 2012 3:31 AM
  • Hi steven,

    We can get all the referenced assemblies via reflection:
    Assembly.GetReferencedAssemblies Method: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getreferencedassemblies.aspx.

    Have a nice day, 

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Monday, January 23, 2012 11:21 AM
  • Well thats just it. I do not control the code at start up. It seems that a referece to the object in the assembly created would be automatically stored somewhere by the application, and that a reference to the object could be obtained through the appdomain object or something like that.

    Like when a form is create a reference can be obtain to it through the Application.OpenForms


    steven frierdich

    Application.OpenForms only works because the Application class is doing what I suggested - it's storing forms (on show) in this static collection.

     

    Reflection will allow you to investigate types, but unless you know of a place where this object is stored, there will be no way to discover the object reference directly.  There is no "global" list of object handles you could use to get an object reference - you'd need to have some other means of attaching to it.

     

    What are you trying to do?  What type of object is this?  Depending on what the actual object is, and whether you have good type information, there may be another approach.


    Reed Copsey, Jr. - http://reedcopsey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    Monday, January 23, 2012 4:31 PM