This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
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 (show other bugs)
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-03-07 19:04 UTC (History)
3 users (show)

See Also:
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

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

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