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. C#
  4. Replace assembly at runtime

Replace assembly at runtime

Scheduled Pinned Locked Moved C#
csharpquestionannouncement
5 Posts 4 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.
  • M Offline
    M Offline
    marca292
    wrote on last edited by
    #1

    Hi, I have a .NET C# application that contains many different assemblies. My start up project contains all assemblies as references, so when I build the application all these assemblies are copied to output directory. Is it possible to replace one of the assemblies at runtime, if it exist a new version of that assembly? Best regards Olof

    D J P 3 Replies Last reply
    0
    • M marca292

      Hi, I have a .NET C# application that contains many different assemblies. My start up project contains all assemblies as references, so when I build the application all these assemblies are copied to output directory. Is it possible to replace one of the assemblies at runtime, if it exist a new version of that assembly? Best regards Olof

      D Offline
      D Offline
      David Ewen
      wrote on last edited by
      #2

      Short answer: No Shortish answer: If you get to it early enough (before any types (or types that reference the types) are instantiated that reference the dlls) you can overwrite them. Long answer: If you need more than the above gives you like being able to swap the types after they have been used you need to create a seperate AppDomain and load the dlls into that. If they get updated you can destroy the AppDomain and create a new one with the new dlls. It all depends on what you are trying to achieve.

      1 Reply Last reply
      0
      • M marca292

        Hi, I have a .NET C# application that contains many different assemblies. My start up project contains all assemblies as references, so when I build the application all these assemblies are copied to output directory. Is it possible to replace one of the assemblies at runtime, if it exist a new version of that assembly? Best regards Olof

        J Offline
        J Offline
        John Gathogo
        wrote on last edited by
        #3

        One way would be to load the assemblies using Reflection. That way, if an assembly changes periodically, you will get the latest

        M 1 Reply Last reply
        0
        • J John Gathogo

          One way would be to load the assemblies using Reflection. That way, if an assembly changes periodically, you will get the latest

          M Offline
          M Offline
          marca292
          wrote on last edited by
          #4

          Hi, a lot of the types declared in the assembly I want to update at runtime are used both in this assembly and in other assemblies. And since a lot of people are working in the project at the same time it's not easy to make a bigger reorganization of the source files.

          1 Reply Last reply
          0
          • M marca292

            Hi, I have a .NET C# application that contains many different assemblies. My start up project contains all assemblies as references, so when I build the application all these assemblies are copied to output directory. Is it possible to replace one of the assemblies at runtime, if it exist a new version of that assembly? Best regards Olof

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            The traditional way to approach this would be to use Dependency Injection to inject the appropriate DLL at runtime. The best way to do this is to not hardcode your type references, but rather you would work against interfaces which the concrete classes would implement. There are many benefits to doing this such as creating more testable objects, improving the loose cohesion of the system, etc.

            I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            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