Skip to content

Finalizer crashes because of FileSystemWatcher Dispose exception in FileSystemWatcher_mobile.cs #7338

Closed

Description

@snakefoot

Steps to Reproduce

  1. Create FileSystemWatcher from NetStandard-library.
  2. FileSystemWatcher constructor fails with NotImplementedException
  3. Finalizer thread attempts to cleanup afterwards and calls FileSystemWatcher.Dispose that fails with NotImplementedException (Unhandled exception)

See also NLog/NLog#1946 (comment)

Could be nice that FileSystemWatcher.Dispose did not throw exceptions, since it is already protected by FileSystemWatcher-constructor throwing NotImplementedException .

Strange that Finalizer-thread runs naked, and can take down the entire application if cleaning up an object that has a bad Dispose-method.

Current Behavior

Crashes with unhandled exception:

Unhandled Exception: System.NotImplementedException: The method or operation is not implemented. at System.IO.FileSystemWatcher.Dispose (System.Boolean disposing) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/src/mono/mcs/class/System/System.IO/FileSystemWatcher_mobile.cs:62
at System.ComponentModel.Component.Finalize () [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/src/mono/mcs/class/referencesource/System/compmod/system/componentmodel/Component.cs:35

Expected Behavior

Doesn't crash

On which platforms did you notice this

[ x] macOS
[ ] Linux
[ ] Windows

Version Used:

Xamarin.Mac.framework/Versions/4.0.0.216

Stacktrace

Unhandled Exception: System.NotImplementedException: The method or operation is not implemented. at System.IO.FileSystemWatcher.Dispose (System.Boolean disposing) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/src/mono/mcs/class/System/System.IO/FileSystemWatcher_mobile.cs:62
at System.ComponentModel.Component.Finalize () [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/4.0.0.216/src/mono/mcs/class/referencesource/System/compmod/system/componentmodel/Component.cs:35

Activity

  1. changed the title [-]Finalizer crashes because of FileSystemWatcher Dispose[/-] [+]Finalizer crashes because of FileSystemWatcher Dispose in NetStandard[/+] on Feb 28, 2018
  2. changed the title [-]Finalizer crashes because of FileSystemWatcher Dispose in NetStandard[/-] [+]Finalizer crashes because of FileSystemWatcher Dispose exception in FileSystemWatcher_mobile.cs[/+] on Feb 28, 2018
  3. akoeplinger commented on Feb 28, 2018

    @akoeplinger
    Member

    I agree we should remove the exception from Dispose().

    @marek-safar any thoughts on enabling FSW for Xamarin.Mac?

  4. marek-safar commented on Mar 1, 2018

    @marek-safar
    Member

    We should have FSW everywhere as it's included in netstandard

  5. akoeplinger commented on Mar 1, 2018

    @akoeplinger
    Member

    Filed #7371 for tracking enabling FSW on more platforms.

  6. ArgusMagnus commented on Mar 22, 2018

    @ArgusMagnus

    I ran into the same problem today with an app which was previously working. I was able to work around this by deriving from the FileSystemWatcher and override the Dispose method:

    static bool CanHaveFileSources { get; } = false;
    
    sealed class FileSystemWatcherTest : FileSystemWatcher
    {
    	protected override void Dispose(bool disposing)
    	{
    		try { base.Dispose(disposing); }
    		catch { }
    	}
    }
    // ...
    try
    {
    	using (var tmp = new FileSystemWatcherTest())
    	{
    		CanHaveFileSources = true;
    	}
    }
    catch { CanHaveFileSources = false; }
    
  7. added a commit that references this issue on Apr 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions