Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 拒绝访问路径(Xamarin/Android)_C#_Android_Xamarin_Visual Studio 2015_Windows 10 - Fatal编程技术网

C# 拒绝访问路径(Xamarin/Android)

C# 拒绝访问路径(Xamarin/Android),c#,android,xamarin,visual-studio-2015,windows-10,C#,Android,Xamarin,Visual Studio 2015,Windows 10,我正在运行Windows 10、Visual Studio 2015和Xamarin。我对Xamarin是一个新手(只是为了让大家了解情况)。在我最近更新之后,我现在有一个问题。更新之前,我的应用程序正在运行。我所有的文件都是只读的,在更新之前我没有任何问题。除此之外,我还重建了该项目,并为该项目进行了“清理和重建”。我已经用我拥有的多个应用程序尝试过了,而其他应用程序没有这个问题。问题我得到以下错误 06-26 13:51:55.108 I/MonoDroid( 6985): UNHANDLE

我正在运行Windows 10、Visual Studio 2015和Xamarin。我对Xamarin是一个新手(只是为了让大家了解情况)。在我最近更新之后,我现在有一个问题。更新之前,我的应用程序正在运行。我所有的文件都是只读的,在更新之前我没有任何问题。除此之外,我还重建了该项目,并为该项目进行了“清理和重建”。我已经用我拥有的多个应用程序尝试过了,而其他应用程序没有这个问题。问题我得到以下错误

06-26 13:51:55.108 I/MonoDroid( 6985): UNHANDLED EXCEPTION:
06-26 13:51:55.142 I/MonoDroid( 6985): System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/defaultDirectory/users.ini" is denied.
06-26 13:51:55.142 I/MonoDroid( 6985):   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) [0x001f1] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   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, System.String msgPath, System.Boolean bFromProxy, System.Boolean useLongPath, System.Boolean checkHost) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions,string,bool,bool,bool)
06-26 13:51:55.142 I/MonoDroid( 6985):   at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize, System.Boolean checkHost) [0x00067] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding, System.Boolean detectEncodingFromByteOrderMarks, System.Int32 bufferSize) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at System.IO.StreamReader..ctor (System.String path, System.Boolean detectEncodingFromByteOrderMarks) [0x0000d] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at System.IO.StreamReader..ctor (System.String path) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at (wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (string)
06-26 13:51:55.142 I/MonoDroid( 6985):   at System.IO.File.OpenText (System.String path) [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at QykAndroidApp.AdminLoginActivity.decryptUsers () [0x00033] in <65a7af1659a443738d96e6c2b7534ab2>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at QykAndroidApp.AdminLoginActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0008a] in <65a7af1659a443738d96e6c2b7534ab2>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <d855bac285f44dda8a0d8510b679b1e2>:0 
06-26 13:51:55.142 I/MonoDroid( 6985):   at (wrapper dynamic-method) System.Object:28564880-3429-412d-9c61-4f5bb9fc103e (intptr,intptr,intptr)
06-26 13:51:55.153 W/art     ( 6985): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
An unhandled exception occured.
06-26 13:51:55.108 I/MonoDroid(6985):未处理的异常:
06-26 13:51:55.142 I/MonoDroid(6985):System.UnauthorizedAccessException:对路径“/storage/emulated/0/defaultDirectory/users.ini”的访问被拒绝。
06-26 13:51:55.142 I/MonoDroid(6985):在System.IO.FileStream..ctor(System.String路径、System.IO.FileMode模式、System.IO.FileAccess访问、System.IO.FileShare共享、System.Int32 bufferSize、System.Boolean匿名、System.IO.FileOptions选项)[0x001f1]输入:0
06-26 13:51:55.142 I/MonoDroid(6985):在System.IO.FileStream..ctor(System.String路径、System.IO.FileMode模式、System.IO.FileAccess访问、System.IO.FileShare共享、System.Int32 bufferSize、System.IO.FileOptions选项、System.String msgPath、System.Boolean bFromProxy、System.Boolean useLongPath、System.Boolean checkHost)[0x00000]中:0
06-26 13:51:55.142 I/MonoDroid(6985):at(包装器远程调用检查)System.IO.FileStream:.ctor(字符串,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int,System.IO.FileOptions,字符串,bool,bool)
06-26 13:51:55.142 I/MonoDroid(6985):在System.IO.StreamReader..ctor(System.String path,System.Text.Encoding Encoding,System.Boolean detectEncodingFromByteOrderMarks,System.Int32 bufferSize,System.Boolean checkHost)[0x00067]输入:0
06-26 13:51:55.142 I/MonoDroid(6985):在System.IO.StreamReader..ctor(System.String path,System.Text.Encoding Encoding,System.Boolean detectEncodingFromByteOrderMarks,System.Int32 bufferSize)[0x00000]英寸:0
06-26 13:51:55.142 I/MonoDroid(6985):在System.IO.StreamReader..ctor(System.String路径,System.Boolean detectEncodingFromByteOrderMarks)[0x0000d]中:0
06-26 13:51:55.142 I/MonoDroid(6985):在System.IO.StreamReader..ctor(System.String路径)[0x00000]中:0
06-26 13:51:55.142 I/MonoDroid(6985):at(包装器远程调用检查)System.IO.StreamReader:.ctor(字符串)
06-26 13:51:55.142 I/MonoDroid(6985):在System.IO.File.OpenText(System.String路径)[0x00000]中:0
06-26 13:51:55.142 I/MonoDroid(6985):位于QykAndroidApp.AdminLoginActivity.decryptUsers()[0x00033]in:0
06-26 13:51:55.142 I/MonoDroid(6985):在QykAndroidApp.AdminLoginActivity.OnCreate(Android.OS.Bundle savedInstanceState)[0x0008a]中:0
06-26 13:51:55.142 I/MonoDroid(6985):在Android.App.Activity.n_OnCreate_Landroid_os_Bundle(System.IntPtr jnienv,System.IntPtr native_uthis,System.IntPtr native_savedInstanceState)[0x0000f]in:0
06-26 13:51:55.142 I/MonoDroid(6985):at(包装器动态方法)系统。对象:28564880-3429-412d-9c61-4f5bb9fc103e(intptr、intptr、intptr)
06-26 13:51:55.153 W/art(6985):JNI RegisternActiveMethods:尝试为android.runtime.JavaProxyThrowable注册0个本机方法
发生未处理的异常。
我读过几篇文章,比如(我在谷歌上发布了第三项搜索,因为我几乎阅读了排名靠前的所有内容)。我曾尝试以管理员身份运行该程序,并且该目录对任何人都具有开放访问权限

对于任何对我如何访问我的文件的代码感到好奇的人,它在下面

 private List<string> readUsers()
    {
        adminUsers = new List<string>();
        try
        {
            StreamReader readerForFile;

            //create checks for making sure the card is mounted, the directory is found, and the file is found. 
            var filePath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "defaultDirectory/users.ini");

            File.SetAttributes(filePath, FileAttributes.Normal);

            if (File.Exists(filePath))
            {
                //Reads enttire document
                //var fillContent = File.ReadAllText(filePath);
                readerForFile = File.OpenText(filePath);
                if (readerForFile == null) { return null; }
                else
                {
                    string line = "";
                    int counter = 0;
                    while ((line = readerForFile.ReadLine()) != null)
                    {
                        adminUsers.Add(line);
                        counter++;
                    }
                }
            }

        }
        catch (IOException e)
        {
            //You'll need to add proper error handling here
            alert.SetMessage("File was not found. " + e).SetNeutralButton("Okay", delegate { QuestionActivity.exit(); }).Create().Show();
        }

        return adminUsers;
    }
private List readUsers()
{
adminUsers=新列表();
尝试
{
StreamReader readerForFile;
//创建检查以确保卡已装入、目录已找到以及文件已找到。
var filePath=Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path,“defaultDirectory/users.ini”);
SetAttributes(filePath,FileAttributes.Normal);
if(File.Exists(filePath))
{
//阅读enttire文档
//var fillContent=File.ReadAllText(文件路径);
readerForFile=File.OpenText(文件路径);
如果(readerForFile==null){return null;}
其他的
{
字符串行=”;
int计数器=0;
而((line=readerForFile.ReadLine())!=null)
{
adminUsers.Add(行);
计数器++;
}
}
}
}
捕获(IOE异常)
{
//您需要在此处添加正确的错误处理
SetMessage(“未找到文件”。+e).SetNeutralButton(“好的”,委托{QuestionActivity.exit();}).Create().Show();
}
返回管理员用户;
}

您应该在Android中启用读取外部存储和写入外部存储权限。 您可以跟随此博客在运行时启用权限

“我的应用程序在更新之前工作。”您可以尝试从设备卸载应用程序,然后重新部署。