我通过右键单击解决方案 => 添加 => 新文件 => 其他 => 应用程序配置文件,将 app.config 文件添加到我的项目中,并将其命名为“LightmapUpdater.exe.config”。 “LightmapUpdater.exe”是我的可执行文件的名称。这是配置文件里面的内容:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<dllmap dll="libIL" target="/opt/local/lib/libil.dylib" />
</configuration>
无论我故意在文件中犯什么错误,它都会一直忽略它们,甚至没有给我任何警告。应该是这样吗?为什么它会忽略我在那里输入的所有内容?在编译之前,如何确保单声道在我的配置文件中?我一定是遗漏了一些步骤。
最佳答案
它对我有用。对于可执行文件 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'.
关于macos - Mono 完全忽略 app.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19521978/