Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Load dll client side

Load dll client side

Scheduled Pinned Locked Moved WPF
question
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adriaan Davel
    wrote on last edited by
    #1

    Hi, I'm working on extensibility of my Silverlight application and would like to load a dll on the client side and invoke methods based on an interface, can it be done? Any links to good articles? I would prefer to not include it in my build of my application, ie the client can upload extensions, and then invoke them, so its not a referenced library...

    ____________________________________________________________ Be brave little warrior, be VERY brave

    M A 3 Replies Last reply
    0
    • A Adriaan Davel

      Hi, I'm working on extensibility of my Silverlight application and would like to load a dll on the client side and invoke methods based on an interface, can it be done? Any links to good articles? I would prefer to not include it in my build of my application, ie the client can upload extensions, and then invoke them, so its not a referenced library...

      ____________________________________________________________ Be brave little warrior, be VERY brave

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Adriaan Davel wrote:

      would like to load a dll on the client side and invoke methods based on an interface, can it be done?

      Yes. Given a Stream to an assembly DLL, you can use the AssemblyPart.Load method to load the assembly into the current app domain and get an Assembly object. Then you can use Assembly.CreateInstance to create instances of classes in the assembly.

      Stream sourcestream = ...;
      AssemblyPart assemblypart = new AssemblyPart();
      Assembly assembly = assemblypart.Load(sourcestream);
      IMyInterface myinterfaceobject = assembly.CreateInstance("MyNamespace.SomeClassThatInheritsFromIMyInterface") as IMyInterface;
      

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      A 1 Reply Last reply
      0
      • A Adriaan Davel

        Hi, I'm working on extensibility of my Silverlight application and would like to load a dll on the client side and invoke methods based on an interface, can it be done? Any links to good articles? I would prefer to not include it in my build of my application, ie the client can upload extensions, and then invoke them, so its not a referenced library...

        ____________________________________________________________ Be brave little warrior, be VERY brave

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Here's a version that searches the assembly for the first instance of a class that implements your interface, and if found, creates an instance of that class:

        IMyInterface myinterfaceobject = null;
        Stream sourcestream = ...;
        AssemblyPart assemblypart = new AssemblyPart();
        Assembly assembly = assemblypart.Load(sourcestream);
        foreach (Type t in assembly.GetTypes())
        {
            if (null != t.GetInterface("IMyInterface", false))
            {
                myinterfaceobject = assembly.CreateInstance(t.FullName) as IMyInterface;
                break;
            }
        }
        if (myinterfaceobject != null)
        {
            // Do something!
        }
        

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • M Mark Salsbery

          Adriaan Davel wrote:

          would like to load a dll on the client side and invoke methods based on an interface, can it be done?

          Yes. Given a Stream to an assembly DLL, you can use the AssemblyPart.Load method to load the assembly into the current app domain and get an Assembly object. Then you can use Assembly.CreateInstance to create instances of classes in the assembly.

          Stream sourcestream = ...;
          AssemblyPart assemblypart = new AssemblyPart();
          Assembly assembly = assemblypart.Load(sourcestream);
          IMyInterface myinterfaceobject = assembly.CreateInstance("MyNamespace.SomeClassThatInheritsFromIMyInterface") as IMyInterface;
          

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          A Offline
          A Offline
          Adriaan Davel
          wrote on last edited by
          #4

          Hi Mark, Thanks for the reply. Loading the assembly and creating an instance is easy enough, my challenge is getting the assembly to the client side in the best possible way as it will not ship with the .xap file, any ideas around that?

          ____________________________________________________________ Be brave little warrior, be VERY brave

          M 1 Reply Last reply
          0
          • A Adriaan Davel

            Hi Mark, Thanks for the reply. Loading the assembly and creating an instance is easy enough, my challenge is getting the assembly to the client side in the best possible way as it will not ship with the .xap file, any ideas around that?

            ____________________________________________________________ Be brave little warrior, be VERY brave

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Adriaan Davel wrote:

            my challenge is getting the assembly to the client side in the best possible way as it will not ship with the .xap file, any ideas around that?

            Maybe try downloading it like you would any resource. For example, Using the WebClient class' OpenReadAsync() method to download the assembly DLL, you'll get a stream in the OpenReadCompleted event which you can use in the sample code I posted.

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            A 1 Reply Last reply
            0
            • M Mark Salsbery

              Adriaan Davel wrote:

              my challenge is getting the assembly to the client side in the best possible way as it will not ship with the .xap file, any ideas around that?

              Maybe try downloading it like you would any resource. For example, Using the WebClient class' OpenReadAsync() method to download the assembly DLL, you'll get a stream in the OpenReadCompleted event which you can use in the sample code I posted.

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              A Offline
              A Offline
              Adriaan Davel
              wrote on last edited by
              #6

              I've played with OpenReadAsync and it works well, but it means that I have to download the assembly everytime, which I'm trying to avoid...

              ____________________________________________________________ Be brave little warrior, be VERY brave

              M 1 Reply Last reply
              0
              • A Adriaan Davel

                I've played with OpenReadAsync and it works well, but it means that I have to download the assembly everytime, which I'm trying to avoid...

                ____________________________________________________________ Be brave little warrior, be VERY brave

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Adriaan Davel wrote:

                it means that I have to download the assembly everytime, which I'm trying to avoid...

                The XAP file is downloaded every time too, along with every resource not included in the XAP file. Cached versions will be used if available. The only option you have without user intervention is isolated storage.

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                A 1 Reply Last reply
                0
                • A Adriaan Davel

                  Hi, I'm working on extensibility of my Silverlight application and would like to load a dll on the client side and invoke methods based on an interface, can it be done? Any links to good articles? I would prefer to not include it in my build of my application, ie the client can upload extensions, and then invoke them, so its not a referenced library...

                  ____________________________________________________________ Be brave little warrior, be VERY brave

                  A Offline
                  A Offline
                  Adriaan Davel
                  wrote on last edited by
                  #8

                  I'm also looking at MEF for this, still not sure if it will work for this (or even how it works :))

                  ____________________________________________________________ Be brave little warrior, be VERY brave

                  1 Reply Last reply
                  0
                  • M Mark Salsbery

                    Adriaan Davel wrote:

                    it means that I have to download the assembly everytime, which I'm trying to avoid...

                    The XAP file is downloaded every time too, along with every resource not included in the XAP file. Cached versions will be used if available. The only option you have without user intervention is isolated storage.

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    A Offline
                    A Offline
                    Adriaan Davel
                    wrote on last edited by
                    #9

                    Thanks, right now I'm trying to understand MEF, else Isolated Storage is probably the right option...

                    ____________________________________________________________ Be brave little warrior, be VERY brave

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups