Xamarin iOS System.UnauthorizedAccessException:读取共享文件时拒绝访问路径

问题描述 投票:0回答:1

此错误是新错误,从 VS2019 更新到 VS2022 (Windows) 后开始出现。还有一些 macOS 更新(现在是 Ventura 13.7)。共享代码工作正常,但似乎缺少安全设置 - 希望是一个简单的疏忽。

以下是应用程序的片段。关于从哪里开始寻找原因有什么建议吗?

信息.plist:

<dict> <key>CFBundleTypeName</key> <string>Public plain-text</string> <key>LSItemContentTypes</key> <array> <string>public.plain-text</string> </array> </dict>

AppDelegate.cs:
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
    MyModule mm = new MyModule();
    mm.AddFile(url.Path);
    return true;
}

我的模块.cs:
public class MyModule
{
    public void AddFile(string url)
    {
        ...
        var text = File.ReadAllText(url); << Exception line >>
        ...
    }
}

异常消息:

{System.UnauthorizedAccessException: Access to the path "/private/var/mobile/Containers/Shared/AppGroup/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/File Provider Storage/xxxxx.txt" is denied. at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x0026e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/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 access, System.IO.FileShare share, System.Int32 bufferSize, System.IO.FileOptions options) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.IO/FileStream.cs:106 at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) [0x00055] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/IO/StreamReader.cs:182 at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/IO/StreamReader.cs:167 at System.IO.File.InternalReadAllText (System.String path, System.Text.Encoding encoding) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/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/Versions/Current/src/Xamarin.iOS/external/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 }

解决了。答案可以在
c# ios xamarin xamarin.forms share
1个回答
0
投票

中找到

© www.soinside.com 2019 - 2024. All rights reserved.