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
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!
Now that I have hacked past the ProviderIdentifer, I also cannot access the DocumentStorageUrl property. I get the same UI thread error.
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 . This is the same (default) setting for release builds.
PR master https://github.com/xamarin/xamarin-macios/pull/1836
Can you provide proper steps or description for verifying this bug.
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.