Satisfying runtime indirect references

I am using C # and VS2010. I have a dll that I reference in my project (as a dll link, not a project link). This dll (a.dll) refers to another dll that my project does not use directly, call it b.dll. None of them are in the GAC.

My project compiles fine, but when I run it from Visual Studio, I get an exception that cannot be found in b.dll. It is not copied to the bin directory when compiling my project.

What is the best way to get b.dll in the bin directory so that it can be found at runtime. I thought of four options.

  • Use the post compile step to copy b.dll to the bin directory
  • Add b.dll to my project (as a file) and specify a copy in the output directory, if new
  • Add b.dll as a dll link for my project.
  • Use ILMerge to combine b.dll with a.dll

I don't like 3 at all because it makes b.dll visible to my project, the other two are like hacks. Are there any other solutions? What is the β€œright” way? Can the dependency injection platform allow and load b.dll?

+4
source share
1 answer

You can add the b.dll file to your project and install "Copy to output directory".

If b.dll already (somewhere) on end-user computers, you can handle the AssemblyResolve event and load it yourself.

If you want, you can compile it as an embedded resource in your project (add the file, then install the Build Action in the Embedded Resource), and then load it into the AssemblyResolve handler)

EDIT : Example:

 static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args) { if (args.Name == "b") return Assembly.Load(path); } 
+1
source

Source: https://habr.com/ru/post/1309114/


All Articles