Bug 42935 - System.IO.FileSystemWatcher throws NotImplementedException
Summary: System.IO.FileSystemWatcher throws NotImplementedException
Status: Tracked in Related Links
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 9.6 (iOS 9.3)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Alexis Christoforides
Depends on:
Reported: 2016-07-29 22:24 UTC by andrew.tarr
Modified: 2018-11-29 06:48 UTC (History)
10 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 42935 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Tracked in Related Links

Description andrew.tarr 2016-07-29 22:24:35 UTC
The summary says it all. Example:

    var watcher1 = new System.IO.FileSystemWatcher("somefilepath.txt");
    var watcher2 = new System.IO.FileSystemWatcher();

Both throw a NotImplementedException.
Comment 1 Manuel de la Peña [MSFT] 2016-08-01 08:54:00 UTC

Please can you provide the exact version of the runtime? The easiest way to get exact version information is to use the  "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the 
"Copy Information" button).

Apart from the above, can you give use a little more context, for example, what type of project were you trying to build? (iOS, Console app, etc..)



PS: I cannot reproduce your issue with the following version:

=== Xamarin Studio Business ===

Version 6.1 (build 4373)
Installation UUID: 01060673-5bee-4cf4-a4c2-5e36a18d39a2
	Mono 4.4.1 (mono-4.4.0-branch-c7sr0/4747417) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404010000

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: (Xamarin Business)
Android SDK: /Users/mandel/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		6.0   (API level 23)

SDK Tools Version: 25.1.6
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 7.3 (10183.3)
Build 7D175

=== Xamarin.Mac ===

Version: (Xamarin Business)

=== Xamarin.iOS ===

Version: (Xamarin Business)
Hash: 6e41b65
Branch: core-data-issues
Build date: 2016-07-26 18:15:15+0200

=== Build Information ===

Release ID: 601004373
Git revision: 852a87304bbbd9c26e81bbb2428dafc6145f1601
Build date: 2016-05-31 01:09:06-04
Xamarin addins: d6b49aee9d3b2f75a1eea84b8ad3b2d1d4fd77c0
Build lane: monodevelop-lion-master

=== Operating System ===

Mac OS X 10.11.6
Darwin Mandels-Pro-Work.local 15.6.0 Darwin Kernel Version 15.6.0
    Thu Jun 23 18:25:34 PDT 2016
    root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Addin Maker 1.3.2
StyleCop Support
Comment 2 andrew.tarr 2016-08-01 14:46:53 UTC
This is an iOS project that is recording videos and the intent was to have FileWatcher watch for the creation of the video file. My runtime version is as follows:

=== Xamarin Studio Enterprise ===

Version 6.0.2 (build 70)
Installation UUID: 0c5e86ef-77a3-4ba5-b020-2588dc44e162
	Mono 4.4.2 (mono-4.4.0-branch-c7sr1/b430435) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404020008

=== Xamarin.Profiler ===

Not Installed

=== Xamarin.Android ===

Version: (Visual Studio Enterprise Trial)
Android SDK: /Users/atarr/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

Android Designer EPL code available here:

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin Inspector ===

Hash: 4d868da
Branch: master
Build date: Mon Jun 13 19:14:13 UTC 2016

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.iOS ===

Version: (Visual Studio Enterprise Trial)
Hash: a5ae61c
Branch: cycle7-sr1
Build date: 2016-07-20 23:23:58-0400

=== Xamarin.Mac ===

Version: (Visual Studio Enterprise Trial)

=== Build Information ===

Release ID: 600020070
Git revision: 30f7c18e8acbca2124c88a2ba9014123097c53ab
Build date: 2016-07-21 16:55:52-04
Xamarin addins: 451cc4c4640551a72356d8a85a4f15ff55fcb661
Build lane: monodevelop-lion-cycle7-sr1

=== Operating System ===

Mac OS X 10.11.6
Darwin andrews-mbp-2 15.6.0 Darwin Kernel Version 15.6.0
    Thu Jun 23 18:25:34 PDT 2016
    root:xnu-3248.60.10~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector
Comment 3 Manuel de la Peña [MSFT] 2016-08-02 16:08:40 UTC
Thanks, I'll downgrade and will try to reproduce the issue.
Comment 4 Manuel de la Peña [MSFT] 2016-08-04 09:28:57 UTC
I can confirm this happens in an iOS project (while it won't happen in a terminal one) due to this: https://github.com/mono/mono/blob/master/mcs/class/System/System.IO/FileSystemWatcher_mobile.cs
Comment 5 Andres Castro 2016-11-19 14:49:35 UTC
Also getting this within a MacOS project. Is there a work around?
Comment 6 Attila Tamás Zimler 2017-06-03 09:46:24 UTC
Here is a workaround, from this, I’m assuming that this is strictly a compilation problem on how the libraries for Mac are compiled:

1) From this location: https://github.com/mono/mono/tree/master/mcs/class/System/System.IO, you will need to following files:
- DefaultWatcher.cs
- FAMWatcher.cs
- FileAction.cs
- FileSystemWatcher.cs
- IFileWatcher.cs
- InotifyWatcher.cs
- KeventWatcher.cs
- NullFileWatcher.cs
- SearchPattern.cs
- WindowsWatcher.cs

2) You will need to change the namespace of the FileSystemWatcher.cs to something other than System.IO, so that you can tell away the two classes.

3) Fix up compilation problems:
- In the above files for all FileSystemWatcher references insert your namespace in front of it.
- for all Consts.Assembly… press F12 to browse into the assembly and copy out the string constant - the value of the constant is internal, so you will not have access to it in the source code, but copy pasting it will make sure you reference the same DLLs.
- Add missing namespaces.

4) in FileSystemWatcher.cs around line:120, change
 mode = InternalSupportsFSW() 

 mode = 3

that seems to work on macOS Sierra.

Unfortunately, since not all files are with the same copyright headers, I have no time to figure out if I could redistribute a modified binary as a compiled DLL from a separate project, so somebody at Xamarin will have to fix this up during the compilation or whoever wishes to use it can apply the workaround.

Please note: the sources are from the same location as the problematic FileSystemWatcher_mobile.cs.
Comment 7 ctclements 2017-10-10 20:11:32 UTC
I am experiencing this when creating an OSX Cocoa project with Target Framework Xamarin.Mac Modern.  I assume this is because Modern is more aimed at iOS/Android.  Unfortunately, I need to use Modern as it supports netstandard 2.0, while Full doesn't.  

Will the work around above help me?  Is there anyway to make a Xamarin.Mac Modern project recognize that it is not just a mobile project?
Comment 8 Attila Tamás Zimler 2017-10-10 20:15:25 UTC
ctclements: I'm using the workaround since I've posted it in a project and seems to work fine. The only thing that sometimes annoys me, is that I had to duplicate non-related code too to replace the FileSystemWatcher with the custom included one, but that is more a code organization issue, not anything related to the workaround itself.
Comment 9 ctclements 2017-10-10 20:36:32 UTC
Attila:  Could you explain your work around a little more to me?  I'm afraid I'm lost around step 3.  I downloaded the necessary files, and then changed all of their namespaces away from System.IO to a custom one.  I'm a little lost on how to complete the steps after that, specifically I'm not familiar with "Consts.Assembly and how to browse into the assembly code.
Comment 10 Attila Tamás Zimler 2017-10-10 20:55:36 UTC
Step 3 is actually editing the downloaded code, Consts."Assembly" is inside the code. For example, FileSystemWatcher.cs:228, 		[TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]

If you open the source code with a Visual IDE those usually have the F12 key bound to go to definition, so you go to the definition of Consts.AssemblySystem_Design in this case and replace it textually to "System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

Keep in mind that the above Assembly information is for the version that I've built together 3 months ago, the assembly name could have been changed and I also typed the text so I could even mistype it - especially the PublicKeyToken. Point is that this is just making the code compile without actually changing it.
Comment 11 Attila Tamás Zimler 2017-10-10 20:56:58 UTC
At the end your line should look something like this:
[TypeConverter("System.Diagnostics.Design.StringValueConverter, " + "System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
Comment 12 Manuel de la Peña [MSFT] 2017-10-11 09:55:55 UTC
I've pinged @chamos to take a look since he is the mac os x team lead.
Comment 13 Chris Hamons 2017-10-11 14:38:38 UTC
I'm taking a look at this, but I want to post one correction:

"Unfortunately, I need to use Modern as it supports netstandard 2.0, while Full doesn't."

This is incorrect. I wrote up a long description here (https://medium.com/@donblas/xamarin-mac-and-netstandard2-708a06890302)

but the short answer is that you can add:


in your top property group and things should just work. If you are on the d15-3 release, you may need to add

<Reference Include=”netstandard” />

in your reference section manually as well.
Comment 14 ctclements 2017-10-11 15:37:03 UTC
Chris:  I tried this, but unfortunately it didn't get me too far.  After I added those lines and retargeted my packages, my Mac App instantly crashes on NSApplication.Init(); with error "Could not load file or assembly 'System.Data.Common' or one of its dependencies".
Comment 15 Chris Hamons 2017-10-11 15:53:09 UTC
Please create a forum post (https://forums.xamarin.com/categories/mac) or a separate XM bug for that specific issue, with the full build log (preferably a sample showing the issue).
Comment 16 Matt Soucoup 2017-10-25 15:45:20 UTC
I don't want to pile on... originally the bug was reported for iOS and then workarounds were noted for Mac. This is still happening on iOS. Would it be helpful if I opened a new bugzilla or provided updated info on the specifics here?
Comment 17 Attila Tamás Zimler 2017-10-25 16:45:23 UTC
Matt: I don't know anything about if this is fixable on iOS or if it is a good idea to implement a file system watcher on a mobile device, but the problem is actually a FileSystemWatcher.cs vs. FileSystemWatcher_mobile.cs, so I think the fact of macOS vs. iOS is part of the problem.
Comment 18 Matt Soucoup 2017-10-25 17:54:40 UTC
Thanks for the quick reply Attila - I had a feeling that FileSystemWatcher didn't make sense to implement on a mobile device. I will go back to the author of the library I am trying to use in order to see if they can do anything.

Appreciate the help.