Search code examples
c#dlllog4netlinq-to-excel

Use LinqToExcel in dll, when main executable uses old log4net version


I am writing an extension (dll) for a 3rd party program. The main program is using log4net version 1.2.10. I want to use LinqToExcel to read Excel files, which also depends on a newer version of log4net.

When I use the log4net.dll from the main executable I get an System.BadImageFormatException when using the extension.

When I replace the log4net.dll with the newer version from LinqToExcel I get an System.NullReferenceException from the main program.

Is there a way to get this to work, or do I have to use an other way to read Excel files?

WORKAROUND: I did remove all logging from LinqToExcel and did rebuild it without the log4net reference.


Solution

  • If you have ownership over the main program, you can update the log4net version 1.2.10 with the one your other dependent assembly uses (if that's newer). Theoretically, log4net should be backward compliant. Though I see that the latest LinqToExcel release 1.10.1 uses older versions of log4net than your main app, specifically 1.2.9 for the release and 1.2.1.40796 for NuGet.

    Since your main app uses a newer assembly and don't wish to modify LinqToExcel, you could wrap the reference to log4net 1.2.10 into an ILMerge-d assembly. Conversely, you could have your own LinqToExcel build that uses only log4net 1.2.10.