序列化问题:System.UnauthorizedAccessException
我收到此错误: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我遇到的问题是我基本上会创建一个名为“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.
这是您的方法,执行将数据添加到数据库的代码在哪里?
另外,您还必须检查实际创建的数据库,您是否这样做了?如果其他项目使数据库连接更容易一些。
尝试检查您访问的数据库的权限。
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.