Click here to Skip to main content
15,742,704 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)

I want to return a list containing DirectoryInfo , but i am getting an error of de-serialization.

Please assist me how can i do this?

Code Snippet--

        private System.Collections.Generic.List<DirectoryInfo> GetSubDirectories(string directory)
                DirectoryInfo directoryPath = new DirectoryInfo(directory);
               // DirectoryInfo dir = new DirectoryInfo(directoryPath);
                List<DirectoryInfo> result = new List<DirectoryInfo>();
                //List<DirectoryInfo> resultChild = new List<DirectoryInfo>();
                DirectoryInfo[] childDirectories;

                childDirectories = directoryPath.GetDirectories();

                //HelpInfo help = new HelpInfo();
                //help.Count = 0;
                foreach (DirectoryInfo childDirectory in childDirectories)
                    // Add the child directory to the result list


                // return the full list of all subdirectories of the one passed in.
                return result;
            catch (Exception ex) { DPS.Logging.LogMessage(NLog.LogLevel.Error,"Error Message -"+ex.Message+" "+"Error InnerException"+ ex.InnerException);}
            return null;
Updated 12-Mar-13 13:11pm
Sandeep Mewara 12-Mar-13 10:19am    
Elaborate more. What were you doing. Update question with it.
Richard MacCutchan 12-Mar-13 10:47am    
We cannot guess what error you received; please try and formulate clear and detailed questions.
Rupesh Kumar Tiwari 12-Mar-13 12:30pm    
You should show us the directoryInfo object. You can do that by taking a snapshot of that object and show to us.
Sergey Alexandrovich Kryukov 12-Mar-13 19:21pm    
Are you sure you really need a list DirectoryInfo, not directory names? You take child directories only on first level of hierarchy. Are you sure you only need one level?
In what line do you have the exception thrown? I don't see any serialization...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900