Bug 42935 - System.IO.FileSystemWatcher throws NotImplementedException
Summary: System.IO.FileSystemWatcher throws NotImplementedException
Status: CONFIRMED
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries (show other bugs)
Version: XI 9.6 (iOS 9.3)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Alexis Christoforides
URL:
Depends on:
Blocks:
 
Reported: 2016-07-29 22:24 UTC by andrew.tarr
Modified: 2017-10-11 15:53 UTC (History)
9 users (show)

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


Attachments

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 2016-08-01 08:54:00 UTC
Hello,

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..)

Regards,

Manuel

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
Runtime:
	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: 6.1.1.1 (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:
https://github.com/xamarin/AndroidDesigner.EPL

=== 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: 2.11.2.44 (Xamarin Business)

=== Xamarin.iOS ===

Version: 9.11.0.44 (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 1.0.1.9
Manifest.addin 0.0.0.0
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
Runtime:
	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: 6.1.2.20 (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:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

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

=== Xamarin Inspector ===

Version: 0.9.0.14
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: 9.8.2.19 (Visual Studio Enterprise Trial)
Hash: a5ae61c
Branch: cycle7-sr1
Build date: 2016-07-20 23:23:58-0400

=== Xamarin.Mac ===

Version: 2.8.2.19 (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 0.9.0.14
Comment 3 Manuel de la Peña 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 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() 

to
 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=2.0.5.0, 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=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
Comment 12 Manuel de la Peña 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:

<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>

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).

Note You need to log in before you can comment on or make changes to this bug.