Bug 53075 - Can't access ProviderIdentifier in NSFileProviderExtension
Summary: Can't access ProviderIdentifier in NSFileProviderExtension
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 10.4 (C9)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.2
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2017-03-06 14:33 UTC by tmrog
Modified: 2017-05-05 11:21 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: No
Last known good build:


Attachments
Project to illustrate the bug (601.50 KB, application/zip)
2017-03-06 14:33 UTC, tmrog
Details


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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description tmrog 2017-03-06 14:33:15 UTC
Created attachment 20152 [details]
Project to illustrate the bug

This fails in the out of the box template BTW.

In an NSFileProviderExtension you need to create a FileCoordinator. To do that you need the ProviderIdentifer.

However, the NSFileProviderExtension code does not run on the UI thread.

I get this error: "UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread."

stack trace is this:
at UIKit.UIApplication.EnsureUIThread () [0x00023] in /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/UIKit/UIApplication.cs:88 
at UIKit.NSFileProviderExtension.get_ProviderIdentifier () [0x00000] in /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/build/ios/native/UIKit/NSFileProviderExtension.g.cs:263 
at FileProvider.FileProvider.CreateDocumentDirectory () [0x00013] in /ProjectLocation/FileProvider/FileProvider.cs:28 
at FileProvider.FileProvider.StartProvidingItemAtUrl (Foundation.NSUrl url, System.Action`1[T] completionHandler) [0x00008] in /ProjectLocation/FileProvider/FileProvider.cs:77

I have attached a sample project that illustrates the issue.

Also, see here: https://forums.xamarin.com/discussion/89945/cant-access-provideridentifier-in-nsfileproviderextension
Comment 1 Sebastien Pouliot 2017-03-07 03:40:10 UTC
While UIKit is, by default, not thread safe it's not the case here (even if not clearly stated as such in the documentation). The fact that the type purpose is file coordination does imply threading.

The workaround given in the forum is correct. Also this thread check is not done (by default) on release builds (for performance reasons).

Thanks for the bug report!
Comment 2 tmrog 2017-03-07 13:48:46 UTC
Now that I have hacked past the ProviderIdentifer, I also cannot access the DocumentStorageUrl property.  I get the same UI thread error.
Comment 3 Sebastien Pouliot 2017-03-07 14:07:12 UTC
This is a check that applies, by default, to every member of UIKit.* types, i.e. it was not specific to the property you mentioned before.

To disable the feature globally please see [1]. This is the same (default) setting for release builds.

[1] https://developer.xamarin.com/releases/ios/monotouch_6/monotouch_6.0/#Cross-thread_UI_Checks
Comment 4 Sebastien Pouliot 2017-03-07 15:07:05 UTC
PR master https://github.com/xamarin/xamarin-macios/pull/1836
Comment 6 Roshan Mankani 2017-05-05 07:34:54 UTC
Hello @tmrog,
Can you provide proper steps or description for verifying this bug.
Comment 7 tmrog 2017-05-05 11:21:51 UTC
Sure.  If you go back to my initial description you'll see I was creating an out of the box file provider extension.  That extension would crash when it was run.  

1. Build the app I provided
2. Set the file provider extension as the startup project
3. Run the extension and launch an app like Pages to invoke the FileProviderBug doc picker.
4. The FileProvider will crash in its constructor when it tries to access ProviderIdentifier.