Serialization problem : System.UnauthorizedAccessException

烂漫一生 提交于 2019-12-02 06:34:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!