3

ServiceStack's new support for Razor v2 uses a FileSystemWatcher to detect changes to tracked view files and mark them as invalid so they'll be recompiled at the next request.

This is great for debugging as it lets you edit your views and not rebuild/restart your project.

On Mono (currently running 3.0.10) on my Mac OS X (Mountain Lion) there is apparently a Mono bug where the FileSystemWatcher doesn't raise Changed events for file changes. Furthermore, it also doesn't raise any events for files in a subdirectory, even if IncludeSubdirectories is set to true.

2 Answers 2

5

After investigating and testing various things out, I found several older bug reports against Mono about failing FileSystemWatcher functionality.

The workaround to the problem is found in the Mono source: https://github.com/mono/mono/blob/master/mcs/class/System/System.IO/FileSystemWatcher.cs

string managed = Environment.GetEnvironmentVariable ("MONO_MANAGED_WATCHER");
...
if (String.Compare (managed, "disabled", true) == 0)
    NullFileWatcher.GetInstance (out watcher);
else
    DefaultWatcher.GetInstance (out watcher);

If you set the environment variable MONO_MANAGED_WATCHER to anything (I set it to "enabled") then it will use the DefaultWatcher which is a managed implementation, and it works on Mac OS X.

So during my application startup, I added:

Environment.SetEnvironmentVariable("MONO_MANAGED_WATCHER", "enabled");

and voila, my Razor views are recompiled after I save a new version. :)

1

it works but mono begins to consume a lot of CPU time: ~70% of one core.

1
  • 1
    That's right - I just updated my answer to indicate it's a workaround and not an "answer". I highly recommend using this workaround if you're working in a cold place and need to warm up!! Jun 27, 2014 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.