它对我有用。对于可执行文件 Test773.exe,该文件被命名为 Test773.exe.config,并且指定的 dll 映射发生。该文件与exe文件在同一目录中吗?MonoDevelop 中是否标有“复制到输出”选项?
应用程序的源代码:
using System;
using System.Runtime.InteropServices;
namespace Test773
{
class MainClass
{
public static void Main(string[] args)
{
Funkcja();
}
[DllImport("libIL")]
public static extern void Funkcja();
}
}
配置文件的内容是从您的问题中复制粘贴的。执行效果:
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
编辑:
要跟踪/调试这个,你可以使用MONO_LOG_LEVEL
. 例如:
MONO_LOG_LEVEL=debug mono Test773.exe | grep config
结果是:
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'.