问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/4354731/serialization-problem-system-unauthorizedaccessexception