问题描述
我得到这个错误:
类型'System.UnauthorizedAccessException的未处理的异常出现在mscorlib.dll
I am getting this error:An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
其他信息:拒绝访问路径C:\\用户\\风暴基尔南\\桌面(NEW)原型开发工具包\\实验室\\实验室\\ BIN \\ 86 \\调试\\ lol.dataf'被拒绝
Additional information: Access to the path 'C:\Users\Storm Kiernan\Desktop(NEW)Archetype Development Kit\Laboratory\Laboratory\bin\x86\Debug\lol.dataf' is denied.
从尝试通过这个code到任何对象序列化:
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);
}
}
此项目位于我的桌面上,还有另外一个在我的文档文件夹中VS /项目有code几乎相同,这一点,它运行得很好。唯一的区别是它不是通用的。任何想法?
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?
推荐答案
行,所以我是有这个问题是,我基本上会创建一个文件夹称为lol.dataf,并尝试写一个文件夹并没有一个文件。因此,事实上,它不能被写入。编译器应该印有:I.D.10-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.
这篇关于序列化问题信息:System.UnauthorizedAccessException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!