DLL不会加载,如果引用了某个特定的其他DLL。

huangapple go评论60阅读模式
英文:

DLL is not loaded if a certain other DLL is referenced

问题

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 my Class 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.
英文:

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.

答案1

得分: 2

你可以使用ILMerge来合并A.dll和log4net.dll。这样,您就不需要在项目中引入额外的log4net.dll。减少了DLL冲突的可能性。

英文:

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

huangapple
  • 本文由 发表于 2023年7月6日 18:36:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627939.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定