Reputation: 81
I'm using Mono's mcs on Ubuntu. I have a Monogame program that has to locate the Monogame libraries in a subdirectory called "libs". It compiles fine, but when it comes to runtime it gives me an error saying it can't find it.
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'MonoGame.Framework, Version=3.1.2.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. File name: 'MonoGame.Framework, Version=3.1.2.0, Culture=neutral, PublicKeyToken=null' [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'MonoGame.Framework, Version=3.1.2.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. File name: 'MonoGame.Framework, Version=3.1.2.0, Culture=neutral, PublicKeyToken=null'
My compiler flags are as follows:
mcs -r:libs/MonoGame.Framework.dll -target:winexe -out:main.exe *.cs
Not even a warning from the compiler, but it can't run. I've tried a lot of variations of these flags and I can't find an option to static compile (and I don't really want to). It runs fine when the libraries are in the same directory, but in a subdirectory it doesn't work. I've tried supposed solutions such as "AppDomain.CurrentDomain" and "Environment.SetEnvironmentVariable" but that didn't work and honestly it's a bad idea.
Upvotes: 0
Views: 1380
Reputation: 44181
The subdirectory is not going to be part of the search path. If you must put it in a subdirectory, I would recommend that you solve this with an application config file which specifies a private search path:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="libs" />
</assemblyBinding>
</runtime>
</configuration>
Upvotes: 1