Can't read custom config section after using ILMerge

Subject: I create console application (documents parser) and use NLog for logging processing events. After build i use ILMerge tool for merging all DLLs to one executable file (it needed for more confortable using result tool)

If i use external NLog.config xml-file for loggers configuration - it's work good (before and after merging all dll-s and exe to single file)

So, problem: But if i trying to use "nlog" section in docsloader.exe.config file - it's work only without merging by IL (if all dll and exe files in separately mode). If i firstly merge result to single file and run docsloader.exe i see:

Unhandled Exception: System.Configuration.ConfigurationErrorsException: An error occurred creating the configuration section handler for nlog: Could not load file or
 assembly 'NLog' or one of its dependencies. The system cannot find the file specified. (C:\d\projects\_\out\docsloader.exe.Config line 5)
---> System.IO.FileNotFoundException: Could not load file or assembly 'NLog' or one of its dependencies. The system cannot find the file specified.

docsloader.exe.config (first 20 strings)

      <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />

<nlog xmlns="">
        <target name="console" type="Console" layout="${date:format=HH\:mm\:ss}|${level}| ${message}" />
        <target name="file"  type="File" fileName="${basedir}/docsloader.log" layout="${date}|${level}| ${message}" />
        <logger name="*" minlevel="Debug" writeTo="console" />
        <logger name="*" minlevel="Trace" writeTo="file" />

    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>


ILMerge command:

C:\d\projects\_\ILMerge\ILMerge.exe /out:"C:\d\projects\_\_\out\docsloader.exe" "C:\d\projects\_\_\bin\Release\docsloader.exe" "C:\d\projects\_\_\bin\Release\*.dll" /target:exe /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /lib:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /wildcards

echo Coping docsloader.exe.config...
cp C:\d\projects\_\_\bin\Release\docsloader.exe.config C:\d\projects\_\_\out\docsloader.exe.config

PS: If i remove -section and create NLog.config - it's work correctly. Thank you!


The error comes from the type reference NLog.Config.ConfigSectionHandler, NLog which refers to NLog dll (after the comma), which no longer exists as it's now merged.

You can replace it by NLog.Config.ConfigSectionHandler, docsloader and it'll probably work.

Need Your Help

Excel 2007 file writer in C# results in a corrupt file

c# excel-2007 binary-data binaryreader binarywriter

I am using a BinaryReader to read an Excel 2007 file from an Exchange mailbox using a OWA, the file is then written to disk using a BinaryWriter. My problem is that the two files don't match when ...

Is using @@TRANCOUNT useful?

c# sql-server

I have a simple SP that will either do an INSERT or an UPDATE depending on the existence or non-existence of data in a table.