0

I'm in the seventh circle of DLL hell.

Here's my situation:

  • Class library project needs to use some DLLs, call them A.dll and B.dll.
  • A.dll depends on log4net.dll, so I have to include that one too.
  • If B.dll is not referenced, or if all uses of it are commented, log4net.dll is loaded (I can see it in the Modules window at runtime) and everything works correctly.
  • The moment I add and use B.dll I get an exception. A.dll says it can't find log4net.dll, and if I look in the Modules window I can see that log4net.dll is indeed not there.

Things I've tried:

  • Placing A.dll in a dedicated folder along with its log4net.dll does not help.
  • Installing the log4net NuGet package instead of using the log4net.dll does not work.
  • However installing the log4net NuGet package in the projects that use myClass Library solves the problem (but I can't require users of my library to install the log4net NuGet).

It looks like if I use B.dll the log4net.dll stops being loaded, and I don't understand why. My best guess is that B.dll includes a version of log4net itself which conflicts with the one I load for A.dll, but then why doesn't it show up in the Modules window?

Additional information:

  • A is Modbus.dll, and B is Regatron.G5.dll. I use them to control some machines.
  • Modbus.dll requires 1.2.10.0.
  • My class library uses NET 4.7.2. I also have a console project that I use to test my library, which uses 4.7.2 as well.
carllacan
  • 310
  • 3
  • 10
  • https://github.com/awaescher/Fusion – Mitch Wheat Jul 06 '23 at 10:42
  • 1
    My guess is that there's a versioning conflict somewhere - but without any specifics, we can't be more precise. If you could provide some minimal way of reproducing the problem, we could look into it... otherwise, Mitch's Fusion link is your best bet. We don't be able to help without more info. (We don't even know what your project type is, or which version of .NET you're targeting...) – Jon Skeet Jul 06 '23 at 10:43
  • I kept it abstract because I thought it would be a common problem, but I've added some additional concrete information now. I have a minimal reproduction example, but I can't upload an entire VS project here. Should I copy the .csproj of the class library instead? – carllacan Jul 06 '23 at 11:02
  • Using NModbus? Is there any reason you can't use a more recent version of it that doesn't depend on log4net? You say you can't require users of your library to install log4net Nuget but you're already doing that by using a version of NModbus that requires it. – Hank Jul 06 '23 at 19:44
  • I need to use that .dll for comatibility reasons with legacy code. What I mean about installing log4net is that until now (meaning until I included the Regatron.dll) I could just include the log4net DLL with my class library, and users of the library didn't need to install anything. It would be a step backwards if newer versions of it required the user to install the NuGet. – carllacan Jul 07 '23 at 06:43
  • @carllacan If my answer is helpful to you, you can mark it so that it can help more people – wenbingeng-MSFT Jul 10 '23 at 01:59
  • Sure, I just haven't had a chance to try it out yet, maybe today. – carllacan Jul 10 '23 at 07:48
  • @carllacan Please feel free to let know if you have any question. – wenbingeng-MSFT Jul 12 '23 at 10:04

1 Answers1

2

I have a method here that used to save the project in a dll conflict:

You can use ILMerge to merge A.dll and log4net.dll. In this way, you do not need to introduce additional log4net.dll in the project. Reduced chance of dll conflicts

wenbingeng-MSFT
  • 1,546
  • 1
  • 1
  • 8