序列化问题:System.UnauthorizedAccessException

发布于 2024-10-06 05:01:36 字数 758 浏览 0 评论 0原文

我收到此错误: mscorlib.dll 中发生类型为“System.UnauthorizedAccessException”的未处理异常

附加信息:访问路径“C:\Users\Storm Kiernan\Desktop(NEW)Archetype Development Kit\Laboratory\Laboratory\bin\x86\Debug\lol” .dataf' 被拒绝。

尝试通过此代码序列化任何对象:

    public static void BinarySerialize<T>(this T t, string path)
    {
        DirectoryInfo directoryInfo = new DirectoryInfo(path);
        directoryInfo.EnsureDirectory();

        using (FileStream stream = new FileStream(directoryInfo.FullName, FileMode.OpenOrCreate))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, t);
        }
    }

该项目位于我的桌面上,我的文档文件夹中的 VS/Projects 中还有另一个项目,其代码几乎与此相同,并且运行良好。唯一的区别是它不通用。有什么想法吗?

I am getting this error:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

Additional information: Access to the path 'C:\Users\Storm Kiernan\Desktop(NEW)Archetype Development Kit\Laboratory\Laboratory\bin\x86\Debug\lol.dataf' is denied.

From trying to serialize any object via this code:

    public static void BinarySerialize<T>(this T t, string path)
    {
        DirectoryInfo directoryInfo = new DirectoryInfo(path);
        directoryInfo.EnsureDirectory();

        using (FileStream stream = new FileStream(directoryInfo.FullName, FileMode.OpenOrCreate))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(stream, t);
        }
    }

This project is located on my desktop, there is another in the VS/Projects in my Documents folder that has code almost identical to this and it runs just fine. The only difference being its not generic. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢绝鈎搭 2024-10-13 05:01:36

好吧,我遇到的问题是我基本上会创建一个名为“lol.dataf”的文件夹,并尝试写入文件夹而不是文件。因此事实上它无法被写入。编译器应该打印:ID10-T,但遗憾的是,它没有。谢谢你们所有的帮助。

OK so the problem I was having was that I would basically create a folder called "lol.dataf" and try to write to a folder and not a file. Hence the fact that it could not be written to. The compiler should have printed : I.D.10-T but alas, it did not. Thank you for all your help guys.

帅气尐潴 2024-10-13 05:01:36

这是您的方法,执行将数据添加到数据库的代码在哪里?

另外,您还必须检查实际创建的数据库,您是否这样做了?如果其他项目使数据库连接更容易一些。

尝试检查您访问的数据库的权限。

This is your method where is the code to execute adding data to the database?

Also your going to have to check your actual created database have you done this? If the other project made the database its abit easyier connecting.

Try check the permissions on the database your accessing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文