System.UnauthorizedAccessException is triggered in our Xamarin iOS app when studying a shared file, both from one other app or by a public folder.
This error is new and began after updating from VS2019 to VS2022 (Home windows). There have been additionally numerous macOS updates (now Ventura 13.7). The sharing code works tremendous however there appears to be a safety setting lacking – hopefuly a easy oversight.
Under are snippets from the app. Any ideas on the place to start out searching for the trigger?
data.plist:
CFBundleTypeName
Public plain-text
LSItemContentTypes
public.plain-text
AppDelegate.cs:
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary choices)
{
MyModule mm = new MyModule();
mm.AddFile(url.Path);
return true;
}
MyModule.cs:
public class MyModule
{
public void AddFile(string url)
{
...
var textual content = File.ReadAllText(url); << Exception line >>
...
}
}
Exception message:
{System.UnauthorizedAccessException: Entry to the trail "/personal/var/cell/Containers/Shared/AppGroup/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/File Supplier Storage/xxxxx.txt" is denied.
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess entry, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean nameless, System.IO.FileOptions choices) [0x0026e] in /Library/Frameworks/Xamarin.iOS.framework/Variations/Present/src/Xamarin.iOS/mcs/class/corlib/System.IO/FileStream.cs:274
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess entry, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions choices) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Variations/Present/src/Xamarin.iOS/mcs/class/corlib/System.IO/FileStream.cs:106
at System.IO.StreamReader..ctor (System.String path, System.Textual content.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) [0x00055] in /Library/Frameworks/Xamarin.iOS.framework/Variations/Present/src/Xamarin.iOS/exterior/corefx/src/Widespread/src/CoreLib/System/IO/StreamReader.cs:182
at System.IO.StreamReader..ctor (System.String path, System.Textual content.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Variations/Present/src/Xamarin.iOS/exterior/corefx/src/Widespread/src/CoreLib/System/IO/StreamReader.cs:167
at System.IO.File.InternalReadAllText (System.String path, System.Textual content.Encoding encoding) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Variations/Present/src/Xamarin.iOS/exterior/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:303
at System.IO.File.ReadAllText (System.String path) [0x00026] in /Library/Frameworks/Xamarin.iOS.framework/Variations/Present/src/Xamarin.iOS/exterior/corefx/src/System.IO.FileSystem/src/System/IO/File.cs:282
at [App].MyModule.AddFile (System.String fullPath) [0x00002] in C:xxxx...xxxx.cs:187 }