Adding New References at Runtime...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Juande

    #1

    Adding New References at Runtime...

    Hello,

    My application needs load some dll's at runtime, Is there any way to do it?,
    can you show me a working example code?

    Many thanks


  • Herfried K. Wagner [MVP]

    #2
    Re: Adding New References at Runtime...

    "Juande" <a@b.com> schrieb:[color=blue]
    > My application needs load some dll's at runtime, Is there any way to do
    > it?[/color]

    Take a look at the documentation for 'System.Reflect ion.Assembly.Lo ad*'.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • Juande

      #3
      Re: Adding New References at Runtime...

      Ok thanks,

      Now other question please, I have the next code;

      Dim Form1 As Form
      Form1 =
      System.Reflecti on.Assembly.Loa dFrom("MyDLL.dl l").CreateInsta nce("MyDLL.Form 2")
      Form1.Show()

      How can I check if any dll is still loaded?

      Many thanks

      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> escribió en el mensaje
      news:OdkhuBcZFH A.2128@TK2MSFTN GP14.phx.gbl...[color=blue]
      > "Juande" <a@b.com> schrieb:[color=green]
      >> My application needs load some dll's at runtime, Is there any way to do
      >> it?[/color]
      >
      > Take a look at the documentation for 'System.Reflect ion.Assembly.Lo ad*'.
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: Adding New References at Runtime...

        "Juande" <a@b.com> schrieb:[color=blue]
        > Dim Form1 As Form
        > Form1 =
        > System.Reflecti on.Assembly.Loa dFrom("MyDLL.dl l").CreateInsta nce("MyDLL.Form 2")
        > Form1.Show()
        >
        > How can I check if any dll is still loaded?[/color]

        The DLL will remain loaded until the appdomain that loaded the DLL and/or
        obtained type information from the DLL will be released. If you want to
        unload a DLL, you'll have to work with a secondary appdomain and remote
        interfaces:

        <URL:http://www.west-wind.com/presentations/DynamicCode/DynamicCode.htm >
        -> "Understand ing how .Net loads code"

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • Cor Ligthert

          #5
          Re: Adding New References at Runtime...

          Juande,

          I am curious, how were you able to produce this question in such a short
          time, did you really investigate this as Herfried sugested?

          Cor


          Comment

          • Juande

            #6
            Re: Adding New References at Runtime...

            Ok,

            I have a large C/S Application (sometimes crashes/quits unexpectedly without
            any error), I want to divide in modules (dll) and then load the needed ones,
            so I've realized a simply application test to load an example dll to check
            System.Reflecti on.Assembly to see how it works, the next step will be check
            if the dll is still loaded to doesn't load again.

            Herfried; Many thanks for your very quick and useful help.

            "Cor Ligthert" <notmyfirstname @planet.nl> escribió en el mensaje
            news:%2318WgfcZ FHA.2124@TK2MSF TNGP14.phx.gbl. ..[color=blue]
            > Juande,
            >
            > I am curious, how were you able to produce this question in such a short
            > time, did you really investigate this as Herfried sugested?
            >
            > Cor
            >[/color]


            Comment

            • Juande

              #7
              Re: Adding New References at Runtime...

              Sorry, but I've got another problem, as you know, I load at runtime my dll,
              this dll contains a class called MyForm, example code on a click button
              event;

              Dim MyDLL As [Assembly]
              MyDLL = System.Reflecti on.Assembly.Loa dFrom("MyDLL.dl l")
              Dim MyForm As Form
              MyForm = MyDLL.CreateIns tance("MyDLL.My Form")
              MyForm.Show()

              This code works fine, but, I want to prevent that if the form is loaded,
              doesn't load other instance, How can I do it?

              Many thanks in advance

              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> escribió en el mensaje
              news:OdkhuBcZFH A.2128@TK2MSFTN GP14.phx.gbl...[color=blue]
              > "Juande" <a@b.com> schrieb:[color=green]
              >> My application needs load some dll's at runtime, Is there any way to do
              >> it?[/color]
              >
              > Take a look at the documentation for 'System.Reflect ion.Assembly.Lo ad*'.
              >
              > --
              > M S Herfried K. Wagner
              > M V P <URL:http://dotnet.mvps.org/>
              > V B <URL:http://classicvb.org/petition/>[/color]


              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: Adding New References at Runtime...

                "Juande" <a@b.com> schrieb:[color=blue]
                > Sorry, but I've got another problem, as you know, I load at runtime my
                > dll, this dll contains a class called MyForm, example code on a click
                > button event;
                >
                > Dim MyDLL As [Assembly]
                > MyDLL = System.Reflecti on.Assembly.Loa dFrom("MyDLL.dl l")
                > Dim MyForm As Form
                > MyForm = MyDLL.CreateIns tance("MyDLL.My Form")
                > MyForm.Show()
                >
                > This code works fine, but, I want to prevent that if the form is loaded,
                > doesn't load other instance, How can I do it?[/color]

                \\\
                Private m_MyForm As Form
                ..
                ..
                ..
                If MyForm Is Nothing Then
                MyForm = MyDll.CreateIns tance(...)
                Else
                MsgBox("Form already instantiated!")
                End If
                ///

                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://classicvb.org/petition/>

                Comment

                • Juande

                  #9
                  Re: Adding New References at Runtime...

                  Herfried thanks for your great patience,

                  When close MyForm and then I want to load it again, it's already
                  instantiated and doesn't show, in some place of my code when from is closing
                  I must to set MyForm = nothing, but where?

                  Thanks

                  "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> escribió en el mensaje
                  news:e88%23ivfZ FHA.3280@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                  > "Juande" <a@b.com> schrieb:[color=green]
                  >> Sorry, but I've got another problem, as you know, I load at runtime my
                  >> dll, this dll contains a class called MyForm, example code on a click
                  >> button event;
                  >>
                  >> Dim MyDLL As [Assembly]
                  >> MyDLL = System.Reflecti on.Assembly.Loa dFrom("MyDLL.dl l")
                  >> Dim MyForm As Form
                  >> MyForm = MyDLL.CreateIns tance("MyDLL.My Form")
                  >> MyForm.Show()
                  >>
                  >> This code works fine, but, I want to prevent that if the form is loaded,
                  >> doesn't load other instance, How can I do it?[/color]
                  >
                  > \\\
                  > Private m_MyForm As Form
                  > .
                  > .
                  > .
                  > If MyForm Is Nothing Then
                  > MyForm = MyDll.CreateIns tance(...)
                  > Else
                  > MsgBox("Form already instantiated!")
                  > End If
                  > ///
                  >
                  > --
                  > M S Herfried K. Wagner
                  > M V P <URL:http://dotnet.mvps.org/>
                  > V B <URL:http://classicvb.org/petition/>[/color]


                  Comment

                  • Herfried K. Wagner [MVP]

                    #10
                    Re: Adding New References at Runtime...

                    "Juande" <a@b.com> schrieb:[color=blue]
                    > When close MyForm and then I want to load it again, it's already
                    > instantiated and doesn't show, in some place of my code when from is
                    > closing I must to set MyForm = nothing, but where?[/color]

                    You may want to add a handler to the form's 'Closed' event using
                    'AddHandler' and set the variable to 'Nothing' there.

                    --
                    M S Herfried K. Wagner
                    M V P <URL:http://dotnet.mvps.org/>
                    V B <URL:http://classicvb.org/petition/>

                    Comment

                    • Juande

                      #11
                      Re: Adding New References at Runtime...

                      Hello Herfried,

                      Finally I got to dispose the instance of MyForm with AddHandler and
                      RemoveHandler, thanks to you.
                      But, every time that I do something about this, problems come to me. The
                      next question is; How can I access to the methods, functions or variables
                      declared into 'MyForm'.

                      One more time, many thanks


                      Comment

                      • Herfried K. Wagner [MVP]

                        #12
                        Re: Adding New References at Runtime...

                        "Juande" <a@b.com> schrieb:[color=blue]
                        > Finally I got to dispose the instance of MyForm with AddHandler and
                        > RemoveHandler, thanks to you.
                        > But, every time that I do something about this, problems come to me. The
                        > next question is; How can I access to the methods, functions or variables
                        > declared into 'MyForm'.[/color]

                        Direct access to the members would require type information to be available
                        at compile-time, for example, an interface which defines the methods the
                        class implements or a design-time reference. Otherwise you'll have to use
                        reflection (namespace 'System.Reflect ion') or 'CallByName' to call methods
                        on the objects.

                        --
                        M S Herfried K. Wagner
                        M V P <URL:http://dotnet.mvps.org/>
                        V B <URL:http://classicvb.org/petition/>

                        Comment

                        Working...