Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin iOS 8 Bundle Resource - Access to the path is denied

I've have a Xamarin iOS project with a file that I have marked as a bundle resource. The file is configured in the project like so:

<BundleResource Include="my\folder\file.xyz" />

I've have been using the following to access the file as a stream:

string ext = Path.GetExtension ("file.xyz");
string filenameNoExt = filename.Substring (0, filename.Length - ext.Length);
string path = Path.Combine ("my/folder", filenameNoExt);
var resourcePathname = NSBundle.MainBundle.PathForResource (path, ext.Substring (1, ext.Length - 1));
var fStream = new FileStream (resourcePathname, FileMode.Open);

It won't work on iOS 8. It worked without issue before iOS 8.

I get the following error:

Access to the path "/private/var/mobile/Containers/Bundle/Application/0E6DD32F-4E6F-4E54-B47E-A91060097E16/myapp.app/my/folder/file.xyz" is denied.

What, exactly, do I need to change to get this to work in iOS 8?

like image 297
sungiant Avatar asked Oct 31 '25 23:10

sungiant


1 Answers

Provide also FileAccess.Read when you create the stream. Otherwise it will throw an UnauthorizedAccessException for read-only files.

like image 152
Krumelur Avatar answered Nov 04 '25 09:11

Krumelur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!