[Mono-dev] Class built by mono throws FileNotFoundException when run on windows

Greg Young gregoryyoung1 at gmail.com
Wed Sep 2 20:33:54 UTC 2015


Use conditional compilation.

On Tuesday, September 1, 2015, Edward Ned Harvey (mono) <
edward.harvey.mono at clevertrove.com> wrote:

> I've always used separate project files on windows and linux, in order to
> include different compiler symbols, in order to make projects build with
> different dependencies. I've been chastised here for doing it, so I'd like
> to find a better way. (Miguel and others tore apart a pull request, saying
> I should never check __MONO__, if I need behavior to be different on
> windows and non-windows, I need to use a runtime check. The problem is, as
> described below, the runtime check can't build or run on windows, so I'd
> like to figure out how it should be done).
>
> Right now, I have a class, which is using Mono.Unix.Native, because of a
> method that does this:
>     if (Type.GetType("Mono.Runtime") != null) {
>         Syscall.chmod(...);
>     }
>
> When built and run on mono, works great. The problem is building and
> running on windows. In order to make it build, I copied Mono.Posix.dll into
> the project and referenced it, with CopyLocal = False. This way,
> Mono.Posix.dll doesn't get copied to the build directory, which is good
> because it's already present on mono systems, and not needed on windows
> systems - the only reason for it to exist in the project is because windows
> can't build without it.
>
> So it builds. But unfortunately, it won't run on windows. It throws
> FileNotFoundException "Mono.Posix.dll" before evaluating the if-clause.
>
> 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?
>
> Hello.cs:
>     using System;
>     namespace helloProject
>     {
>         static class Hello
>         {
>             static void ChangePermsIfNecessary()
>             {
>                 if (Type.GetType("Mono.Runtime") != null) {
>                     MonoSpecific.DoChmod();
>                 }
>             }
>         }
>     }
>
> MonoSpecific.cs:
>     using System;
>     using Mono.Unix.Native;
>     namespace helloProject
>     {
>         static class MonoSpecific
>         {
>             static void DoChmod()
>             {
>                 Syscall.chmod(...);
>             }
>         }
>     }
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com <javascript:;>
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>


-- 
Studying for the Turing test
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20150902/30200904/attachment.html>


More information about the Mono-devel-list mailing list