Xamarin - PhysicalFileProvider ctor not implemented exception
dazinator opened this issue · 6 comments
As a PoC, I have an xamarin android project, and am consuming netstandard
dependencies.
As such, I am able to consume the Microsoft.Extensions.FileProviders.Physical
nuget package.
In my MainActivity
I do this:
var rootPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var fileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(rootPath);
The constructor throws a NotImplementedException
- assuming because there is no watcher implementation ?
Will this ever be implemented? If watching isn't supported on mono droid, then perhaps it can just be disabled instead to allow the file provider to still be used? (i.e defer a NotImplementedException until a call to Watch() is made?)
I think lazy loading the watcher would be a better rather than loading it immediately in the constructor of the physical file provider. If watch() isn't used, the file provider doesn't need to waste resources (or in my case, error) initialising the watcher.
@natemcmaster could you take a look when you have some time?
@dazinator You were right: the root of the issue is #223. The physical file provider wraps System.IO.FileSystemWatcher. We wouldn't implement a file watcher for android -- that's something xamarin would need to implement in its BCL -- but we can fix #223.
Ok, cheers. It feels very weird that I am spinning up an IHostingEnvironment with a physical file provider, on ios and android. The abstraction is almost perfect though as each platform needs to initialise a platform specific root directory and IFileProvider hides this well. I say almost perfect because IHostingEnvironment also exposes a WebRoot directory - which isnt really valid for non web apps, such as an android or ios app, so I have that property simply returning null. Its a shame WebHostBuilder is so web oriented because I can imagine a scenario where you could use WebHostBuilder and a startup class (ConfigureServices etc) to start and configure your xamarin app, in a similar way to asp.net core websites today.
I have raised the above as a separate request: aspnet/Hosting#1119
Ok thanks, i'll close this then in favour of the other one.