[Mono-dev] Class built by mono throws FileNotFoundException when run on windows
robertj at gmx.net
Wed Sep 2 13:25:05 UTC 2015
On 01.09.2015 22:04, Edward Ned Harvey (mono) wrote:
> The workaround I've found is to create a wrapper class MonoSpecific,
> so the if-clause and the Mono.Posix call are not in the same file.
> But this is clearly a hack. Is there a better way?
You're depending on undefined behavior. The workaround is only
working because the JIT compiler is lazily compiling methods,
and won't compile DoChmod() under Windows.
You should mark DoChmod() with
Otherwise the issue might come back unexpectedly.
However, if .NET 5.0 would start to eagerly compile assemblies
(for whatever reason), the issue will come back as well.
A sane and easy solution is to deploy Mono.Posing on Windows side-by-
side with you app.
Even when running on Mono, Mono.Posix should be picked up
from the GAC. Your copy won't be loaded anyway.
The super-sane solution is to abstract these calls away using a
factory and 2 assemblies, one for Windows and one for Mono
which has Mono.Posix as a reference.
More information about the Mono-devel-list