The question is very hard to try to describe:

Purpose: Downloading the dll I need, and the connection (dynamically or otherwise)!

The question itself: I have a dll (Ionic.dll) - to create a file archive!

I want to upload this dll for example to the hosting, and from there when downloading so that my program can connect to this dll and continue working: How can I do this? Here is a piece of code responsible for archiving:

using Ionic.Zip; public class Archive { static string US = Environment.UserName; public static void GO() { try { using (var zip = new ZipFile()) { { zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression; zip.AlternateEncodingUsage = ZipOption.Always; zip.AlternateEncoding = Encoding.UTF8; zip.UseZip64WhenSaving = Zip64Option.AsNecessary; zip.AddDirectory("С:\\Papka"); zip.Save("С:\\Papka"+ "_" + ".zip"); } zip.Dispose(); } } else { } } catch { } } 

Prompt the best way to connect dll dynamically! Most likely the dll will be next to the project to lie next to 1 folder! It would also be not bad to make a check, that is, if there is no necessary dll to make an exception near the exe's, if there is something to connect and start working.

  • See examples with LoadAssembly - nick_n_a
  • 2
    Connect DLL - Grundy
  • Look towards ILMerge - then the hosting will not be needed. - Pavel Mayorov
  • one
    ILMerge is not advisable to use. I tried more than once). In 1 - The weight is more obtained, In the 2nd I observed some errors when the program was running, precisely because of ILMerge! - GooliveR

1 answer 1

You can add a new handler for AppDomain.CurrentDomain.AssemblyResolve and slip the loadable Assembly there. Here is a great set of tips on how to do it best.

 static void Main(string[] args){ AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly; } static Assembly ResolveAssembly(object sender, ResolveEventArgs args){ return Assembly.LoadFile(@"path to the library"); } 

For the case when the library is not yet available, wrap the call to the method that references any type from this library in try-catch. Even if there is only if (false){ ZipFile totallyNotUsedVariable; } inside the method if (false){ ZipFile totallyNotUsedVariable; } if (false){ ZipFile totallyNotUsedVariable; } , a call to such a method will throw an exception.

  • For example we are loading - Grundy
  • @Grundy, oops, I apologize, I overlooked it. I just wanted to give the simplest example of adding a handler. - Surfin Bird
  • Thanks for the specifics) - GooliveR
  • @SurfinBird, you just have to be more careful - Grundy
  • And for example, if there is no dll, you can just exit the program without exception ? - GooliveR