4

I've added an app.config file to my project by right-clicking on the solution => Add => New File => Misc => Application Configuration File, and named it "LightmapUpdater.exe.config". "LightmapUpdater.exe" is the name of my executable. Here's what the config file has inside:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <dllmap dll="libIL" target="/opt/local/lib/libil.dylib" />
</configuration>

No matter what mistakes I intentionally make in the file, it keeps ignoring them, not giving me even a single warning. Is it supposed to be that way? Why is it ignoring everything I type in there? How can I make sure that mono looks inside of my config file before compiling? I must be missing some step.

Ilya Suzdalnitski
  • 52,598
  • 51
  • 134
  • 168

1 Answers1

6

It does work for me. With executable file Test773.exe the file is named Test773.exe.config and the dll mapping specified takes place. Is the file in the same directory as the exe file? Is it marked with a "Copy to output" option in MonoDevelop?

The source code of the application:

using System;
using System.Runtime.InteropServices;

namespace Test773
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Funkcja();
        }

        [DllImport("libIL")]
        public static extern void Funkcja();
    }
}

The content of the config file is copy pasted from your question. The effect of the execution:

Unhandled Exception:
System.DllNotFoundException: /opt/local/lib/libil.dylib
  at (wrapper managed-to-native) Test773.MainClass:Funkcja ()
  at Test773.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.DllNotFoundException: /opt/local/lib/libil.dylib
  at (wrapper managed-to-native) Test773.MainClass:Funkcja ()
  at Test773.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0

EDIT: To trace/debug this you can use MONO_LOG_LEVEL. For example:

MONO_LOG_LEVEL=debug mono Test773.exe | grep config

results in:

Mono: Config attempting to parse: '/usr/lib/mono/4.5/mscorlib.dll.config'.
Mono: Config attempting to parse: '/usr/etc/mono/assemblies/mscorlib/mscorlib.config'.
Mono: Config attempting to parse: '/usr/etc/mono/config'.
Mono: Config attempting to parse: '/home/konrad/.mono/config'.
Mono: Config attempting to parse: '/home/konrad/eksperymenty/Test773/Test773/bin/Debug/Test773.exe.config'.
Mono: Config attempting to parse: '/usr/etc/mono/assemblies/Test773/Test773.config'.
konrad.kruczynski
  • 46,413
  • 6
  • 36
  • 47
  • You're genius, this indeed was the issue! The file wasn't copied to the output directory. Thanks a lot! – Ilya Suzdalnitski Oct 22 '13 at 15:44
  • I would really appreciate it if you could take a look at another issue I'm having here: http://stackoverflow.com/questions/19522244/bundling-dylib-files-with-mono-executable – Ilya Suzdalnitski Oct 22 '13 at 15:47